款待奶牛(treat)

题目描述

FJ有n(1≤n≤2000)个美味的食物,他想卖掉它们来赚钱给奶牛。这些食物放在一些箱子里,它们有些有趣的特性:
(1)这些食物被编号为1~n,每一天FJ可以从这排箱子的头部或者尾部取出食物去卖;
(2)这些食物放得越久,年龄越大,价值越大,食物i有一个初始的价值V(i);
(3)放了a天后,年龄为a,食物最终的价值为V(i)×a。
给定每一个食物的初始价值v(i),请求出FJ卖掉它们后可以获得的最大价值,第一天出售的食物的年龄为1,此后每增加一天食物的年龄就增加1。

输入

第1行:一个整数n;
第i+l行:每行为食物i的初始价值V(i)。

输出

1行:FJ最终可以获得的最大价值。

样例输入

5
1
3
1
5
2

样例输出

43

提示

样例说明:FJ出售这些食物(初始价值1,3,1,5,2)的顺序为:第一天卖掉第1个,第二天卖掉第5个,第三天卖掉第2个,第四天卖掉第3个,第5天卖掉第4个,获得最大的价值 1×1+2×2+3×3+4×1+5×5=43。

分析:又是区间dp,还是很开心的,dp[j][i]表示以j为起点长度为i的最优解(注意:i表示最后i天的决策);

   一大神用记忆化搜索过了,简直666

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=2e3+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,dp[maxn][maxn],a[maxn];
int main()
{
int i,j,k,t;
scanf("%d",&n);
rep(i,,n)scanf("%d",&a[i]);
rep(i,,n)
{
for(j=;j+i<=n+;j++)
{
dp[j][i]=max(dp[j+][i-]+(n-i+)*a[j],dp[j][i-]+(n-i+)*a[j+i-]);
}
}
printf("%d\n",dp[][n]);
//system ("pause");
return ;
}

款待奶牛(treat)的更多相关文章

  1. BZOJ1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果

    1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 4 ...

  2. 1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果

    1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 4 ...

  3. LGOJ P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm

    今天我来给大家带来一片蒟蒻题解 ~~真香 LGOJ P2921  [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题目描述 每年,在威斯康星州,奶牛们都会穿上 ...

  4. 缩点【洛谷P2921】 [USACO08DEC]在农场万圣节Trick or Treat on the Farm

    [洛谷P2921] [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N< ...

  5. 「USACO08DEC」「LuoguP2921」在农场万圣节Trick or Treat on the Farm(tarjan

    题意翻译 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定 ...

  6. 洛谷 P2858 [USACO06FEB]奶牛零食Treats for the Cows

    题目描述 FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving va ...

  7. 「USACO06FEB」「LuoguP2858」奶牛零食Treats for the Cows(区间dp

    题目描述 FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving va ...

  8. P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm(Tarjan+记忆化)

    P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题意翻译 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N< ...

  9. 洛谷——P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm

    P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题意翻译 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N< ...

随机推荐

  1. php+ajax的三级联动下拉菜单

    封装一个三级联动,就可以在任何页面进行引用了 先写个页面引用一下这个js <head> <meta http-equiv="Content-Type" conte ...

  2. php给数组key:value中的key加引号

    public function Ext_json_decode($str, $mode=false){ if(preg_match('/\w:/', $str)){ $str = preg_repla ...

  3. python常用函数年初大总结

    1.常用内置函数:(不用import就可以直接使用) help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像函数一样调用 repr(obj) 得到o ...

  4. Windows常用的监视数据指标

  5. ado vb6

    http://www.cnblogs.com/ywb-lv/articles/2343444.html http://stackoverflow.com/questions/3334102/use-t ...

  6. SQL的自增列重置的方法

    SQL的自增列挺好用,只是开发过程中一旦删除数据,标识列就不连续了 写起来 也很郁闷,所以查阅了一下标识列重置的方法 发现可以分为三种: --- 删除原表数据,并重置自增列 truncate tabl ...

  7. Error configuring application listener of class 报错 解决

    Error configuring application listener of class 次错误是由于工程没有贬义Class文件造成的,clean一下编译一下工程,clean之后进入项目目录查看 ...

  8. OpenGL中shader读取实现

    1.需要shader在OpenGL中工作,必须经过如下过程 2.代码实现 /********** * loadshader.h **********/ #pragma once #define _CR ...

  9. dsplay:table页面合并表格

    在实际项目中经常会遇到合并表格的情形,现在我将自己合并的方法写出来,供大家教参一下,顺便自己也作个备忘. <%@ page language="java" contentTy ...

  10. hiho#1128 : 二分·二分查找

    input 1<=n<=1e6 1<=k<=2*1e9 a1 a2 ... an 1<=an<=2*1e9 output k存在则输出k是第几大的数,否则输出-1 ...