简单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的更多相关文章

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

  2. POJ 3186 Treats for the Cows (动态规划)

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

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

  4. POJ 3186 Treats for the Cows 一个简单DP

    DP[i][j]表示现在开头是i物品,结尾是j物品的最大值,最后扫一遍dp[1][1]-dp[n][n]就可得到答案了 稍微想一下,就可以, #include<iostream> #inc ...

  5. POJ 3186 Treats for the Cows ——(DP)

    第一眼感觉是贪心,,果断WA.然后又设计了一个两个方向的dp方法,虽然觉得有点不对,但是过了样例,交了一发,还是WA,不知道为什么不对= =,感觉是dp的挺有道理的,,代码如下(WA的): #incl ...

  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. POJ3186 Treats for the Cows —— DP

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

  8. (区间dp + 记忆化搜索)Treats for the Cows (POJ 3186)

    http://poj.org/problem?id=3186   Description FJ has purchased N (1 <= N <= 2000) yummy treats ...

  9. 【POJ - 3186】Treats for the Cows (区间dp)

    Treats for the Cows 先搬中文 Descriptions: 给你n个数字v(1),v(2),...,v(n-1),v(n),每次你可以取出最左端的数字或者取出最右端的数字,一共取n次 ...

随机推荐

  1. shell 中的特殊符号的含义

    来源:http://blog.sina.com.cn/s/blog_62a151be0100x9rn.html 第四章 基本功 - 特殊符号 学习撰写 script 最迅速的捷径是观摩别人的 scri ...

  2. Qt之打包发布(NSIS详解)

    来源:http://blog.sina.com.cn/s/blog_a6fb6cc90101fer8.html 发布方式    Qt发布的时候,通常使用两种方式:   (1)静态编译  (2)动态编译 ...

  3. ENC28j60以太网芯片驱动程序简介

    ENC28j60以太网芯片驱动程序简介 ENC28J60 驱动开发要点 enc28J60 和 Arduino (1)——ping通你的Arduino MCU51单片机uIP协议栈+ENC28J60网卡 ...

  4. Hibernate 系列教程16-二级缓存

    pom.xml <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate- ...

  5. Converting between IEEE 754 and Float (Format related

    The float can be converted to well known single-precision IEEE 754 number, why 754? It's the standar ...

  6. centos yum源问题

    在配置CentOS-6.0-x86_64-bin-DVD2.iso作为本地yum源的时候,碰到相当多的问题: -----------------------------------------  问题 ...

  7. WinRAR5.31 注册码

    RAR registration dataState Grid Corporation Of China50000 PC usage licenseUID=5827a0bd1c43525d0a5d64 ...

  8. AI 人工智能 探索 (五)

    我们把做好的 角色 拖到 内存池,如图所示,这样我们可以动态生成角色并给予他 寻路目标. //逗留碰撞 void OnTriggerStay(Collider other) { if (other.t ...

  9. jenkins插件 build-name-setter

    #${BUILD_NUMBER}-${PROJECT_NAME}-${ENV,var="VARIABLENAME"}-${ENV,var="BUILD_USER" ...

  10. 初探JavaScript魅力(五)

    JS简易日历    innerHTML <title>无标题文档</title> <script> var neirong=['一','二','三','四','五' ...