题目链接: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(区间)的更多相关文章

  1. POJ3186:Treats for the Cows(区间DP)

    Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...

  2. kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)

    Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7949   Accepted: 42 ...

  3. POJ3086 Treats for the Cows(区间DP)

    题目链接  Treats for the Cows 直接区间DP就好了,用记忆化搜索是很方便的. #include <cstdio> #include <cstring> #i ...

  4. POJ3186 Treats for the Cows —— DP

    题目链接:http://poj.org/problem?id=3186 Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K To ...

  5. 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 ...

  6. poj3186 Treats for the Cows

    http://poj.org/problem?id=3186 Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  7. Treats for the Cows 区间DP POJ 3186

    题目来源:http://poj.org/problem?id=3186 (http://www.fjutacm.com/Problem.jsp?pid=1389) /** 题目意思: 约翰经常给产奶量 ...

  8. 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- ...

  9. 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 ...

随机推荐

  1. C#中XmlTextWriter读写xml文件详细介绍(转)

    转自http://www.jb51.net/article/35230.htm   .NET中包含了很多支持XML的类,这些类使得程序员使用XML编程就如同理解XML文件一样简单.在这篇文章中,我将给 ...

  2. pdf.js使用教程

    pdf.js框架的魅力所在,为其为HTML5实现的,无需任何本地支持,而且对浏览器的兼容性也是比较好,要求只有一个:浏览器支持HTML5就好了!(不过对于低版本的IE,就只能节哀了!) 据说IE9以上 ...

  3. Android 支付宝以及微信支付快速接入流程

    简介 随着移动支付的普及,越来越多的App采用第三发支付,在这里我们以支付宝为例,做一个快速集成! 一.Android快速实现支付宝支付 1.首先,我们需要前往支付宝开放平台,申请我们的支付功能:ht ...

  4. LayoutInflater的inflate函数用法详解

    LayoutInflater作用是将layout的xml布局文件实例化为View类对象. 获取LayoutInflater的方法有如下三种: LayoutInflater inflater=(Layo ...

  5. 【leetcode】Combination Sum III(middle)

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  6. curl命令 抓取网络数据相应头

    curl --verbose  --data "Password=123&Username=158101068&url=http://m.vancl.com/" & ...

  7. Log4j的使用

    一,Log4j简介 日志的三个目的: 1. 监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工作                      2.跟踪代码运行时轨迹,作为日后审计的依 ...

  8. 25个增强iOS应用程序性能的提示和技巧(高级篇)(1)

    25个增强iOS应用程序性能的提示和技巧(高级篇)(1) 2013-04-16 14:56 破船之家 beyondvincent 字号:T | T 在开发iOS应用程序时,让程序具有良好的性能是非常关 ...

  9. Loadrunner上传与下载文件脚本

    一. 上传脚本 Action() { int uploadImgStatus = 0; //获取上传产品图ID web_reg_save_param_ex("ParamName=imgRan ...

  10. Delphi中的各种字符串、String、PChar、Char数组

    参考博客:http://www.cnblogs.com/pchmonster/archive/2011/12/14/2287686.html 其中的所有代码均在Delphi7下测试通过. Delphi ...