poj3186 Treats for the Cows(区间)
题目链接:http://poj.org/problem?id=3186
题意:第一个数是N,接下来N个数,每次只能从队列的首或者尾取出元素。
ans=每次取出的值*出列的序号。求ans的最大值。
样例 :
input:5
1 2 1 5 2
output:43
思路:区间dp,用两个指针i和j代表区间,dp[i][j]表示这个区间的最大值。
///最开始想想着每次拿值最小的就好了,因为之前没接触过区间dp,就这样naive的交了,意料之中的WA了。
///找到一个范例 eg:1000001 1000002 1000003 1000004 1000005 1 2 3 4 5 6 7 8 9 1000010 这个如果,诶次取最小的得到的就不是最大值
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; int a[];
int dp[][]; int main()
{
int n;
while(cin>>n)
{
for(int i=; i<=n; i++)
cin>>a[i];
memset(dp,,sizeof(dp));
for(int i=; i<=n; i++)
dp[i][i]=a[i]*n;
for(int l=; l<n; l++)
{
for(int i=; i+l<=n; i++)
{
int j=i+l;
dp[i][j]=max((dp[i+][j]+a[i]*(n-l)),(dp[i][j-]+a[j]*(n-l)));
}
}
cout<<dp[][n]<<endl;
}
return ;
}
poj3186 Treats for the Cows(区间)的更多相关文章
- POJ3186:Treats for the Cows(区间DP)
Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...
- kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)
Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7949 Accepted: 42 ...
- POJ3086 Treats for the Cows(区间DP)
题目链接 Treats for the Cows 直接区间DP就好了,用记忆化搜索是很方便的. #include <cstdio> #include <cstring> #i ...
- POJ3186 Treats for the Cows —— DP
题目链接:http://poj.org/problem?id=3186 Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K To ...
- O - Treats for the Cows 区间DP
FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast am ...
- poj3186 Treats for the Cows
http://poj.org/problem?id=3186 Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total S ...
- Treats for the Cows 区间DP POJ 3186
题目来源:http://poj.org/problem?id=3186 (http://www.fjutacm.com/Problem.jsp?pid=1389) /** 题目意思: 约翰经常给产奶量 ...
- P2858 [USACO06FEB]奶牛零食Treats for the Cows
P2858 [USACO06FEB]奶牛零食Treats for the Cows区间dp,级像矩阵取数, f[i][i+l]=max(f[i+1][i+l]+a[i]*(m-l),f[i][i+l- ...
- bzoj1652 / P2858 [USACO06FEB]奶牛零食Treats for the Cows
P2858 [USACO06FEB]奶牛零食Treats for the Cows 区间dp 设$f[l][r]$为取区间$[l,r]$的最优解,蓝后倒着推 $f[l][r]=max(f[l+1][r ...
随机推荐
- codeforces 499B.Lecture 解题报告
题目链接:http://codeforces.com/problemset/problem/499/B 题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 profes ...
- 【Git】笔记2
来源:廖雪峰 安装git(ubuntu) sudo apt-get install git 创建版本库(repository) 在想生成版本库的文件夹下输入: git init 指定用户名和邮箱 g ...
- 【linux】linux下动态库so文件的一些认识
来源:http://mypyg.iteye.com/blog/845915 so其实就是shared object的意思.今天看了上面的博客,感觉好吃力.赶紧做个笔记记录一下.下面的内容大多都是连接中 ...
- Hibernate单向一对多对象关系模型映射
1 hibernate 的对象关系映射 Orm: 类-----表 属性------字段 对象------记录 表:在数据库中存在主外键的关系,反向工厂类是由表生成,在由表生成类的时候,类和类之间存在者 ...
- iOS键盘监听的通知
#pragma mark - 键盘通知回调方法 // 监听键盘的通知 [[NSNotificationCenter defaultCenter] addObserver:self selector: ...
- September 9th 2016 Week 37th Friday
Within you, I lose myself. 有了你,我迷失了自我. I never had such feeling, maybe just because I never invested ...
- [Usaco2015 Feb]Censoring(bzoj 3942)
Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...
- Struts2拦截器之FileUploadInterceptor
一.它能做什么? 借助于这个拦截器我们可以实现文件的上传和下载功能. 理论部分: struts2的文件上传下载功能也要依赖于Apache commons-fileupload和Apache commo ...
- NYOJ之ASCII码排序
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsAAAAIFCAIAAABTaNy/AAAgAElEQVR4nO3dO1LjzMIG4H8T5CyEdF
- 电脑没有关机可能出现发博文dns异常(write)
现在是把装系统的技巧基本掌握,其实弄了这么多次还是有一个突破点,就是安装系统win7选择cd的iso是要ide模式.