POJ 3186 Treats for the Cows 一个简单DP
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的更多相关文章
- 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)
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 dp[i][j]表示的是i到j这段区间获得的a[i]*(j-i)+... ...+a[j-1]*(n-1)+a[j]*n最大值 那么[i,j]这个区间的最大值肯定是由[i+1,j]与[i,j ...
- POJ 3186 Treats for the Cows ——(DP)
第一眼感觉是贪心,,果断WA.然后又设计了一个两个方向的dp方法,虽然觉得有点不对,但是过了样例,交了一发,还是WA,不知道为什么不对= =,感觉是dp的挺有道理的,,代码如下(WA的): #incl ...
- 【POJ - 3186】Treats for the Cows (区间dp)
Treats for the Cows 先搬中文 Descriptions: 给你n个数字v(1),v(2),...,v(n-1),v(n),每次你可以取出最左端的数字或者取出最右端的数字,一共取n次 ...
- kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)
Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7949 Accepted: 42 ...
- 「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 ...
- Luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows 【区间dp】By cellur925
题目传送门 做完A Game以后找道区间dp练练手...结果这题没写出来(哭). 和A Game一样的性质,从两边取,但是竟然还有天数,鉴于之前做dp经常在状态中少保存一些东西,所以这次精心设计了状态 ...
随机推荐
- IE 坑爹的浏览器兼容模式
作为作为Web的前端开发人员,最悲催的莫过于要不断的,不断的去调试各种浏览器的显示效果,个人比较喜欢用火狐浏览器来做开发和调试,对于不怎么懂CSS的我来说,IE的样式调整一看就头大了.对于没有美工的团 ...
- C++内存泄露调试
我在看DirectX Sample的时候,看到以下代码: // Enable run-time memory check for debug builds. #if defined(DEBUG) | ...
- 1016: [JSOI2008]最小生成树计数 - BZOJ
Description 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树中至少有一条边不同,则这两个最小生成树就是不同的 ...
- checkbox复选框样式
随着现代浏览器的流行,纯CSS设置checkbox也变的很是实用,下面会讲到5种与众不同的checkbox复选框. 首先,需要添加一段CSS隐藏所有的Checkbox复选框,下面我们会改变它的外观.要 ...
- Linux下去掉^M的方法
cat -A filename 就可以看到windows下的断元字符 ^M 要去除他,最简单用下面的命令: dos2unix filename 第二种方法: sed -i 's/^M//g ...
- zoj 3380 Patchouli's Spell Cards 概率DP
题意:1-n个位置中,每个位置填一个数,问至少有l个数是相同的概率. 可以转化求最多有l-1个数是相同的. dp[i][j]表示前i个位置填充j个位置的方案数,并且要满足上面的条件. 则: dp[i] ...
- H264/AVC视频解码时AVC1和H264的区别
AVC1与H264的区别 http://blog.csdn.net/qiuchangyong/article/details/6660253 H.264 Video Types The followi ...
- 选择排序的MPI实现
#include "stdafx.h" #include "mpi.h" #include <stdio.h> #include <math. ...
- Java的类演进过程
1.从面向过程到面向对象 在大家最熟悉的C语言中,如果要定义一个复杂的数据类型就用结构体(Struct)来实现,而为结构体的每个操作都定义一个函数,这个函数与结构体本身的定义没有任何关系.程序的重心集 ...
- TSharding:用于蘑菇街交易平台的分库分表组件
tsharding TSharding is the simple sharding component used in mogujie trade platform. 分库分表业界方案 分库分表TS ...