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 ...
随机推荐
- 使用CSS中margin和padding的基础和注意事项
在CSS中,margin和padding是页面布局的主要属性,如何灵活有效使用对于基于DIV+CSS设计网页方法是非常重要的,笔者经常使用且经常误使用,所以根据经验和网上资料整理出切合自己的内容,以备 ...
- CSS3实现圆角效果
利用border-radius属性可以给元素div,input元素等添加圆角效果 后跟 值为这个圆角的半径,即数值越大效果越明显 -webkit-border-top/bottom-left/righ ...
- 【XLL 框架库函数】 Excel/Excel12f
Excel/Excel12f 这两个库函数分别包装了 C API 中的 Excel4 和 Excel12 函数,它们会检查函数没有参数时是否为零,它将表明创建临时的 XLOPER 或 XLOPER12 ...
- HTML/CSS题库
一. 填空题 使用文本编辑器编辑完HTML后,扩展名可以是__html___或___htm__. 表格的标签是____table______,单元格的标签是____td______. 在编辑ta ...
- CentOS 7.0 部署 Django 到运行起来第一个web service
最近在学习Python,今天发现Django如此强大的web框架,不得不来试一试. 1. 安装Python,官网建议用Python3:
- iOS应用架构谈(三):网络层设计方案(上)
iOS客户端应用架构看似简单,但实际上要考虑的事情不少.本文作者将以系列文章的形式来讨论iOS应用架构中的种种问题,本文是其中的第三篇,主要讲网络层设计以及安全机制和优化方案. 前言 网络层在一个Ap ...
- apache ab下载测试
http://httpd.apache.org/docs/2.0/programs/ab.html-->http://httpd.apache.org/docs/current/platform ...
- StoryBoard和代码结合 按比例快速兼容iPhone6/6 Plus教程
转:http://www.cocoachina.com/ios/20141230/10800.html 编者注:根据网友们的评论,文章中的方法有很大的局限性,请谨慎使用! 现在由于苹果公司出了6和6 ...
- 浏览器方法及代码打包成APP的
<script src=" http://static.ydbimg.com/API/YdbOnline.js" type="text/javascript&quo ...
- samba 报错
[root@GitLab data_nfs]# smbclient //localhost/public WARNING: The security=share option is deprecate ...