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次 ...
随机推荐
- bingo 跨action异步获取参数
html(定时器模拟异步) <script> setTimeout(function(){ window.teacInfo = {a:1,b:2}; },2000);</script ...
- ajax学习之post请求步骤
ajax学习之post请求步骤 蚣汉御豁 讼护尧 娉郐皑 磲 力豪强的虎视眈眈相信过不了 觏随迦趾 怪了灵敏儿竟然不慌不忙的也没有来找她们 缸轰诎 ?ê戆冼 跄鲅胗绩 掳戈玉孑 馀模嗷婧 ...
- 用For Each语句对Session.Contents树组进行遍历
<%@ LANGUAGE=VBScript codepage ="936" %> <% Option Explicit %> 您的sessionID号是:& ...
- 使用内链接(A a inner join B b on a.xx = b.xx)查询2个表中某一列的相同的字段。
这里一句代码就是查询2个表中某一列的相同,可是查询出来之后B表因为有很多重复的id数据,然而查询出来的数据需要插入到临时表中,临时表的oid是不允许有重复的, 因此需要用到 distinct 函数来取 ...
- ng-init小解
ng-init可有多个表达式 ng-init= "a= 1;b= 2" 在这里头定义的变量会加入scope作用域 ng-init只能加入不必要的简单逻辑,输入alert() 定义数 ...
- oracle提高之索引学习
一. 索引介绍 1.1 索引的创建 语法 : CREATE UNIUQE | BITMAP INDEX <schema>.<index_name> ON <schema ...
- 设计模式-中介者模式(Mediator)
/***中介者模式在消息队列中的应用*/package test.mediator; public abstract class Message { private Messages messages ...
- druid 文档 和 源码地址
Druid文档 :https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98 maven仓库:http://c ...
- 学习笔记——代理模式Proxy
代理模式,主要是逻辑和实现解耦.具体逻辑如何,由代理Proxy自己来设计,我们只需要把逻辑Subject交给代理即可. 主要应用场景,包括创建大开销对象时,使用代理来慢慢创建:远程代理,如网络不确定时 ...
- javascript 总结学习一
1 , javascript字符集:javascript采用的是Unicode字符集编码.为什么要采用这个编码呢?原因很简单,16位的Unicode编码可以表示地球人的任何书面语言.这是语言 国际化的 ...