博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3186——Treats for the Cows(区间dp)
阅读量:2343 次
发布时间:2019-05-10

本文共 1838 字,大约阅读时间需要 6 分钟。

Description

FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given period time.

The treats are interesting for many reasons:

The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On any day, FJ can retrieve one treat from either end of his stash of treats.
Like fine wines and delicious cheeses, the treats improve with age and command greater prices.
The treats are not uniform: some are better and have higher intrinsic value. Treat i has value v(i) (1 <= v(i) <= 1000).
Cows pay more for treats that have aged longer: a cow will pay v(i)*a for a treat of age a.
Given the values v(i) of each of the treats lined up in order of the index i in their box, what is the greatest value FJ can receive for them if he orders their sale optimally?

The first treat is sold on day 1 and has age a=1. Each subsequent day increases the age by 1.

Input

Line 1: A single integer, N

Lines 2..N+1: Line i+1 contains the value of treat v(i)

Output

Line 1: The maximum revenue FJ can achieve by selling the treats

Sample Input

5

1
3
1
5
2
Sample Output

43

题意是给一串长度为n的数字序列,每次只能从队首或队尾出列,出列时对应的数字乘以出列顺序,最后全部加起来,求最大的值。

学习下区间dp。这种题一般都会枚举区间长度,然后向外按照题意扩展。
本体是从最后卖的物品开始,dp到最先卖出的物品,区间长度当然也是从小到大。

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 2005#define Mod 10001using namespace std;int a[MAXN],dp[MAXN][MAXN]; //dp[i][j]表示i~j这个区间的最优解int main(){ int n; while(~scanf("%d",&n)) { for(int i=1; i<=n; ++i) scanf("%d",&a[i]); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;++i) dp[i][i]=n*a[i]; //初始条件,只有一个数的时候最优解是最后一天卖 for(int len=1; len

转载地址:http://ptcvb.baihongyu.com/

你可能感兴趣的文章
debain 安装amd显卡驱动
查看>>
Java Jacob 打印word文档
查看>>
Java Freemarker 根据模板生成Word
查看>>
Java Mybatis Plus 集成与使用
查看>>
Java 一台电脑部署多个tomcat服务
查看>>
Java WinSw 安装Jar成Windows服务
查看>>
Linux安装Jar成服务
查看>>
Java SSH连接mysql数据库
查看>>
计算机使用常见问题与答案
查看>>
Mysql 触发器的Http请求
查看>>
Mysql 跟踪sql日志
查看>>
搭建一个Vue项目
查看>>
SVN Working Copy Locked 解决方法
查看>>
Java 简单的复习下JDBC 工具类
查看>>
将Java Swing Jar 封装成exe文件
查看>>
端口显示被占用,netstat -aon | findstr却找不到端口的解决方法
查看>>
Linux内核中读写文件数据的方法
查看>>
USB电池充电基础:应急指南(转载)
查看>>
I2C死锁原因及解决方法【转】
查看>>
Ubuntu系统如何安装双网卡及更改网卡名称(eth0改为eth1)
查看>>