题目


1652: [Usaco2006 Feb]Treats for the Cows

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 234  Solved: 185
[Submit][Status]

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.

约翰经常给产奶量高的奶牛发特殊津贴,于是很快奶牛们拥有了大笔不知该怎么花的钱.为此,约翰购置了N(1≤N≤2000)份美味的零食来卖给奶牛们.每天约翰售出一份零食.当然约翰希望这些零食全部售出后能得到最大的收益.这些零食有以下这些有趣的特性:

•零食按照1..N编号,它们被排成一列放在一个很长的盒子里.盒子的两端都有开口,约翰每
  天可以从盒子的任一端取出最外面的一个.
•与美酒与好吃的奶酪相似,这些零食储存得越久就越好吃.当然,这样约翰就可以把它们卖出更高的价钱.
  •每份零食的初始价值不一定相同.约翰进货时,第i份零食的初始价值为Vi(1≤Vi≤1000).
  •第i份零食如果在被买进后的第a天出售,则它的售价是vi×a.
  Vi的是从盒子顶端往下的第i份零食的初始价值.约翰告诉了你所有零食的初始价值,并希望你能帮他计算一下,在这些零食全被卖出后,他最多能得到多少钱.

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

Five treats. On the first day FJ can sell either treat #1 (value 1) or
treat #5 (value 2).

Sample Output

43

OUTPUT DETAILS:

FJ sells the treats (values 1, 3, 1, 5, 2) in the following order
of indices: 1, 5, 2, 3, 4, making 1x1 + 2x2 + 3x3 + 4x1 + 5x5 = 43.


题解


这道题用区间DP,f[i][j]表示最后i-j+1天卖i~j的商品的最大收益。转移见代码。


代码

 /*Author:WNJXYK*/
#include<cstdio>
using namespace std; #define LL long long
#define Inf 2147483647
#define InfL 10000000000LL inline int abs(int x){if (x<) return -x;return x;}
inline int abs(LL x){if (x<) return -x;return x;}
inline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
inline void swap(LL &x,LL &y){LL tmp=x;x=y;y=tmp;}
inline int remin(int a,int b){if (a<b) return a;return b;}
inline int remax(int a,int b){if (a>b) return a;return b;}
inline LL remin(LL a,LL b){if (a<b) return a;return b;}
inline LL remax(LL a,LL b){if (a>b) return a;return b;}
inline void read(int &x){x=;int f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}x=x*f;}
inline void read(LL &x){x=;LL f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}x=x*f;}
inline void read(int &x,int &y){read(x);read(y);}
inline void read(LL &x,LL &y){read(x);read(y);}
inline void read(int &x,int &y,int &z){read(x,y);read(z);}
inline void read(int &x,int &y,int &n,int &m){read(x,y);read(n,m);}
inline void read(LL &x,LL &y,LL &z){read(x,y);read(z);}
inline void read(LL &x,LL &y,LL &n,LL &m){read(x,y);read(n,m);} const int Maxn=;
int n,v[Maxn+];
int f[Maxn+][Maxn+];
int main(){
read(n);
for (int i=;i<=n;i++) read(v[i]);
for (int i=;i<=n;i++)
f[i][i]=v[i]*n;
for (int k=;k<n;k++){
for (int i=;i<=n-k;i++){
int j=i+k;
f[i][j]=remax(v[i]*(n-k)+f[i+][j],v[j]*(n-k)+f[i][j-]);
}
}
printf("%d\n",f[][n]);
return ;
}

BZOJ 1652: [Usaco2006 Feb]Treats for the Cows的更多相关文章

  1. BZOJ 1652: [Usaco2006 Feb]Treats for the Cows( dp )

    dp( L , R ) = max( dp( L + 1 , R ) + V_L * ( n - R + L ) , dp( L , R - 1 ) + V_R * ( n - R + L ) ) 边 ...

  2. bzoj 1652: [Usaco2006 Feb]Treats for the Cows【区间dp】

    裸的区间dp,设f[i][j]为区间(i,j)的答案,转移是f[i][j]=max(f[i+1][j]+a[i](n-j+i),f[i][j-1]+a[j]*(n-j+i)); #include< ...

  3. 【BZOJ】1652: [Usaco2006 Feb]Treats for the Cows(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1652 dp.. 我们按间隔的时间分状态k,分别为1-n天 那么每对间隔为k的i和j.而我们假设i或者 ...

  4. [BZOJ 1652][USACO 06FEB]Treats for the Cows 题解(区间DP)

    [BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yu ...

  5. 【记忆化搜索】bzoj1652 [Usaco2006 Feb]Treats for the Cows

    跟某NOIP的<矩阵取数游戏>很像. f(i,j)表示从左边取i个,从右边取j个的答案. f[x][y]=max(dp(x-1,y)+a[x]*(x+y),dp(x,y-1)+a[n-y+ ...

  6. BZOJ1652 [Usaco2006 Feb]Treats for the Cows

    蒟蒻许久没做题了,然后连动规方程都写不出了. 参照iwtwiioi大神,这样表示区间貌似更方便. 令f[i, j]表示i到j还没卖出去,则 f[i, j] = max(f[i + 1, j] + v[ ...

  7. BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚( 线段树 )

    线段树.. -------------------------------------------------------------------------------------- #includ ...

  8. BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚

    题目 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 553   ...

  9. BZOJ 1653 [Usaco2006 Feb]Backward Digit Sums ——搜索

    [题目分析] 劳逸结合好了. 杨辉三角+暴搜. [代码] #include <cstdio> #include <cstring> #include <cmath> ...

随机推荐

  1. ubuntu 14.04设备flash媒体播放器

    今天是2014年4一个月19日本,就在两天前公布 ubuntu 14.04版本号, 以今天的优势是星期六,西安小雨,所以折腾linux. 我是个有点linux基础的小白.说是有些基础是由于以前在上大学 ...

  2. Unity Editor下对资源进行操作时调用AssetModificationProcessor

    public class Test : UnityEditor.AssetModificationProcessor { private static void OnWillCreateAsset(s ...

  3. 五子棋Web版的开发(二)--整合Spring4.3+hibernate4+Struts2.3

    拖了这么久才把ssh框架给整合完毕,期间发现自己对SSH的知识真的是知之甚少.在整合期间遇到了无数的坑,我还是先把项目地址发一下吧 首先我遇到的第一个问题是 CreateQuery is not va ...

  4. java代理课程测试 spring AOP代理简单测试

    jjava加强课程测试代码 反射. 代理 .泛型.beanUtils等 项目源码下载:http://download.csdn.net/detail/liangrui1988/6568169 热身运动 ...

  5. Android Gradle 配置选项合集

    //让gradle 引入构建安卓app的插件 apply plugin: 'com.android.application' //自定义变量, 使用的时候不需要 ext 前缀 ext { minSdk ...

  6. appium获取app应用的package和 activity。---新手总结(大牛勿喷,新手互相交流)

    从网上搜索的方法: 如下: 1.查看源码 2.日志法a.启动待测apkb.开启日志输出:adb logcat>D:/log.txtc.关闭日志输出:ctrl+cd.查看日志直接搜索 :Displ ...

  7. [转]swift 学习资源 大集合

    今天看到了一个swift的学习网站,里面收集了很多学习资源 [转自http://blog.csdn.net/sqc3375177/article/details/29206779] Swift 介绍 ...

  8. GC算法之串行并行并发

    串行收集器: 用单线程处理所有垃圾回收工作,因为无需多线程交互,所以效率比较高.但是,也无法使用多处理器的优势,所以此收集器适合单处理器机器.当然,此收集器也可以用在小数据量(100M左右)情况下的多 ...

  9. QBoxLayout::setSizeConstraint可以固定窗口的大小,且根据内部控件所占用的位置自动调节大小

    setSizeConstraint(QLayout::SetFixedSize)的功能是保持整个对话框的尺寸保持相对固定.也就是说让布局管理器来调整对话框的大小.举个例子吧:一个上下可扩展对话框,基本 ...

  10. android怎样自定义设置下拉列表样式

    图样: 实现方式: 1.水平布局一个TextView和一个ImageView(小黑箭头) 2.实现点击ImageView的单击事件,弹出PopupWindow 3.PopupWindow中实现下拉列表 ...