DP[i][j]表示现在开头是i物品,结尾是j物品的最大值,最后扫一遍dp[1][1]-dp[n][n]就可得到答案了

稍微想一下,就可以,

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
int v[];
int dp[][];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;++i)
scanf("%d",&v[i]);
memset(dp,,sizeof(dp));
for(int k=n-;k>=;--k)
{
for(int i=;i+k-<=n;++i)
{
if(i>)
dp[i][i+k-]=max(dp[i][i+k-],dp[i-][i+k-]+v[i-]*(n-k));
if(i+k-<n)
dp[i][i+k-]=max(dp[i][i+k-],dp[i][i+k]+v[i+k]*(n-k));
}
}
int ans=;
for(int i=;i<=n;i++)
ans=max(ans,dp[i][i]+v[i]*n);
printf("%d\n",ans);
return ;
}

POJ 3186 Treats for the Cows 一个简单DP的更多相关文章

  1. poj 3186 Treats for the Cows(区间dp)

    Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...

  2. poj 3186 Treats for the Cows(dp)

    Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...

  3. POJ 3186 Treats for the Cows (动态规划)

    Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...

  4. POJ 3186 Treats for the Cows

    简单DP dp[i][j]表示的是i到j这段区间获得的a[i]*(j-i)+... ...+a[j-1]*(n-1)+a[j]*n最大值 那么[i,j]这个区间的最大值肯定是由[i+1,j]与[i,j ...

  5. POJ 3186 Treats for the Cows ——(DP)

    第一眼感觉是贪心,,果断WA.然后又设计了一个两个方向的dp方法,虽然觉得有点不对,但是过了样例,交了一发,还是WA,不知道为什么不对= =,感觉是dp的挺有道理的,,代码如下(WA的): #incl ...

  6. 【POJ - 3186】Treats for the Cows (区间dp)

    Treats for the Cows 先搬中文 Descriptions: 给你n个数字v(1),v(2),...,v(n-1),v(n),每次你可以取出最左端的数字或者取出最右端的数字,一共取n次 ...

  7. kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)

    Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7949   Accepted: 42 ...

  8. 「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 ...

  9. Luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows 【区间dp】By cellur925

    题目传送门 做完A Game以后找道区间dp练练手...结果这题没写出来(哭). 和A Game一样的性质,从两边取,但是竟然还有天数,鉴于之前做dp经常在状态中少保存一些东西,所以这次精心设计了状态 ...

随机推荐

  1. velocity语法

    1.声明变量 #set($var = XXX) 右边可以是以下的内容 Variable reference String literal Property reference Method refer ...

  2. linux 常用命令 集锦

    第一章  LINUX简介及安装    1一.LINUX介绍    1二.LINUX安装    2三.LINUX目录    2四.总结来说:    3第二章 常用命令及帐户管理    4一.linux命 ...

  3. PAT-乙级-1010. 一元多项式求导 (25)

    1010. 一元多项式求导 (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 设计函数求一元多项式的导数.(注:xn(n为整数)的一 ...

  4. python调试总结

    调试通常采用两种方式,打印日志调试以及运行时实时跟踪调试. 一.打印日志: 1. print不要看不起print,这是一切调试的起点,即便是调试Java或者C这种巨麻烦的编译语言,print仍然是常用 ...

  5. 打车APP可能的盈利模式

    贺滨,蓄力的芦苇 竺宇祺.郑子威.党培兵 等人赞同 按现在国内几十家类似start-ups的竞争态势看,嘀嘀现阶段应该还处于烧钱培育市场期. 斗胆想象一下可能的盈利模式: 前向收费(面向用户): 特权 ...

  6. c++实现文本中英文单词和汉字字符的统计

    源代码下载:http://download.csdn.net/detail/nuptboyzhb/4987141 1.统计文本中汉字的频数,为后续的文本分类做基础.对于汉字的统计,需要判断读取的是否为 ...

  7. 【POJ 3335】 Rotating Scoreboard (多边形的核- - 半平面交应用)

    Rotating Scoreboard Description This year, ACM/ICPC World finals will be held in a hall in form of a ...

  8. EdasStudio 开发工具用户手册

    EdasStudio 开发工具用户手册 Edas 开发组2015-8-14 1. 下载安装插件 EdasStudio是EDAS的开发工具,是一个Eclipse Plugins,打开Eclipse的He ...

  9. SQLite入门与分析(二)---设计与概念(续)

    SQLite入门与分析(二)---设计与概念(续)   写在前面:本节讨论事务,事务是DBMS最核心的技术之一.在计算机科学史上,有三位科学家因在数据库领域的成就而获ACM图灵奖,而其中之一Jim G ...

  10. Armitage初始化

    Kali2.0 Armitage初始化步骤如下 (1)点击页面的Armitage按钮 (2)提示Metasploit RPC server is not running,是否启动该服务,选择是 (3) ...