款待奶牛(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. UVA 10480 Sabotage

    最小割+输出方案 #include<cstdio> #include<cstring> #include<string> #include<cmath> ...

  2. VBS一键配置VOIP脚本(其中包括VBS操作JS网页中的按钮事件--直接执行确认按钮中的脚本代码)

    Dim ws,fso,IESet IE = WScript.createobject("InternetExplorer.Application")Set ws = WScript ...

  3. Chapter 1 First Sight——28

    "Which one is the boy with the reddish brown hair?" 那个红褐色头发的男孩是谁? I asked. I peeked at him ...

  4. git基本命令--tag, alias,

    git tag: 列出标签 在 Git 中列出已有的标签是非常简单直观的. 只需要输入 git tag: $ git tag v0. v1. 这个命令以字母顺序列出标签:但是它们出现的顺序并不重要. ...

  5. java中的静态代码块等执行顺序

    http://www.cnblogs.com/naruto469/p/3608459.html public class Print { 2 3 public Print(String s){ 4 S ...

  6. print a float number with 3 digits following

    just use the java's printf function. It is like C's printf. System.out.printf("%.3f\n", x) ...

  7. 【转】mysql函数

    MySQL函数 MySQL数据库提供了很多函数包括: 数学函数: 字符串函数: 日期和时间函数: 条件判断函数: 系统信息函数: 加密函数: 格式化函数: 一.数学函数 数学函数主要用于处理数字,包括 ...

  8. MySQL性能优化的最佳21条经验【转载】

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...

  9. Hidden Word

    Hidden Word time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  10. ios view改变背景图

    一般我们设置 一个view的背景  可以通过  在view上放一个imageView 来显示背景图片 这里介绍另外一种方法 可以直接通过改变view.backgroundColor的值 来达到上面的效 ...