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-1]区间加上端点的较大值推过来的。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=+;
int dp[maxn][maxn];
int a[maxn];
int n; int MAX(int a,int b)
{
if(a>b) return a;
return b;
} int main()
{
scanf("%d",&n);
{
for(int i=; i<=n; i++) scanf("%lld",&a[i]);
memset(dp,,sizeof dp);
int c=n;
for(int i=; i<=n; i++) dp[i][i]=a[i]*c;
c--;
int ans=;
for(int i=; i<=n; i++) //区间长度
{
for(int j=; j<=n; j++) //起点
{
int st=j,en=i+j-;
if(en>n) break;
dp[st][en]=MAX(dp[st+][en]+c*a[st],dp[st][en-]+c*a[en]);
}
c--;
}
printf("%d\n",dp[][n]);
}
return ;
}
POJ 3186 Treats for the Cows的更多相关文章
- 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 ...
- POJ 3186 Treats for the Cows (动态规划)
Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...
- 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 ...
- POJ 3186 Treats for the Cows 一个简单DP
DP[i][j]表示现在开头是i物品,结尾是j物品的最大值,最后扫一遍dp[1][1]-dp[n][n]就可得到答案了 稍微想一下,就可以, #include<iostream> #inc ...
- POJ 3186 Treats for the Cows ——(DP)
第一眼感觉是贪心,,果断WA.然后又设计了一个两个方向的dp方法,虽然觉得有点不对,但是过了样例,交了一发,还是WA,不知道为什么不对= =,感觉是dp的挺有道理的,,代码如下(WA的): #incl ...
- poj3186 Treats for the Cows
http://poj.org/problem?id=3186 Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ3186 Treats for the Cows —— DP
题目链接:http://poj.org/problem?id=3186 Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K To ...
- (区间dp + 记忆化搜索)Treats for the Cows (POJ 3186)
http://poj.org/problem?id=3186 Description FJ has purchased N (1 <= N <= 2000) yummy treats ...
- 【POJ - 3186】Treats for the Cows (区间dp)
Treats for the Cows 先搬中文 Descriptions: 给你n个数字v(1),v(2),...,v(n-1),v(n),每次你可以取出最左端的数字或者取出最右端的数字,一共取n次 ...
随机推荐
- device-mapper: multipath: Failing path recovery【转载】
digoal 2016-04-05 10:09:42 浏览180 评论0 摘要: 由于扇区损坏导致多路径设备failed. 现象如下 : # dmesg : device-mapper: mul ...
- diff
http://www.ruanyifeng.com/blog/2012/08/how_to_read_diff.html 读懂diff 作者: 阮一峰 日期: 2012年8月29日 diff是Un ...
- gre tunnel
http://searchenterprisewan.techtarget.com/tip/GRE-tunnel-vs-IPsec-tunnel-What-is-the-difference Enca ...
- access的保留关键字
access的保留关键字 -A ADD ALL Alphanumeric ALTER AND ANY Application AS ...
- addEventListener与removeEventListener
addEventListener:添加事件监听器 element.addEventListener(event, function, useCapture) event:事件类型,字符串,不要加&qu ...
- remote staspack
输入文件:$HOME/utility/statspack11g/statspack.env, $HOME/utility/statspack11g/dblist,$HOME/utility/stats ...
- C# API 大全
C:\ProgramFiles\MicrosoftVisual Studio .NET\ FrameworkSDK\Samples\ Technologies\ Interop\PlatformInv ...
- c++内存流
1.MemoryStream.h文件内容 ifndef _MEM_STREAM_H_ #define _MEM_STREAM_H_ #include <string> class CMem ...
- fidder 调接口 的 小常识
fidder 调试接口 进入fidder页面 点击 composer Content-Type: application/x-www-form-urlencoded; charset=UTF- ...
- centos6.5 安装git
1.安装编译git时需要的包 # yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel # yum ins ...