题意:给一个数组v,每次可以取前面的或者后面的,第k次取的v[i]价值为v[i]*k,问总价值最大是多少。

区间dp。

区间dp可以不枚举len  直接枚举i和j即可  见代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define maxx 2010
int dp[maxx][maxx];
int main()
{
int n,v[maxx];
while(scanf("%d",&n)!=EOF)
{
for(int i = ;i <= n;i ++)
scanf("%d",&v[i]);
memset(dp,,sizeof(dp));
for(int i=n;i>=;i--)
for(int j=i;j<=n;j++)
{
dp[i][j]=max(dp[i][j],dp[i+][j]+(n-(j-i))*v[i]);
dp[i][j]=max(dp[i][j],dp[i][j-]+(n-(j-i))*v[j]);
}
printf("%d\n",dp[][n]);
}
return ;
}

3186Treats for the Cows(区间dp)的更多相关文章

  1. POJ 3186Treats for the Cows(区间DP)

    题目链接:http://poj.org/problem?id=3186 题目大意:给出的一系列的数字,可以看成一个双向队列,每次只能从队首或者队尾出队,第n个出队就拿这个数乘以n,最后将和加起来,求最 ...

  2. POJ 3186Treats for the Cows (区间DP)

    详见代码 #include <stdio.h> #include <algorithm> #include <string.h> using namespace s ...

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

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

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

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

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

  6. Treats for the Cows 区间DP POJ 3186

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

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

  8. [BZOJ 1652][USACO 06FEB]Treats for the Cows 题解(区间DP)

    [BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yu ...

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

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

随机推荐

  1. Appium新版本不再支持ByName定位了怎么办

    appium版本在1.5以后就不再支持ByName的定位,本文章仅介绍在appium1.6.3/1.6.4/1.6.5版本下如何支持ByName定位,适用于安卓.在使用appium1.5之后的版本时, ...

  2. C# 中使用 Excel

    using System;using System.Collections.Generic;using System.Text;using System.Reflection;using System ...

  3. 关闭VirtualBox虚拟机的时钟同步

    原文链接:关闭VirtualBox虚拟机的时钟同步 在VirtualBox的虚拟机上默认虚拟机的时间是会和物理机同步的,但可以通过下面的命令来关闭 1. 首先查看虚拟机列表 VBoxManage li ...

  4. xampp 安装以及相关问题

    1.安装xampp   说明:xampp集成了mysql,Apache,php,360软件里面就有 2.mysql端口被占用.              如果电脑上已安装MySql数据库,还想用XAM ...

  5. WIN 7 使用shutdown命令设置电脑自动关机

    使用组合键“WIN + R”,在弹出的对话窗“运行”中输入“cmd”,点击“确定”按钮或直接按回车键“Enter”.  设置电脑在一定时间后关机,比如60分钟,在弹出的对话框中,输入“shutdown ...

  6. Datagrip导入导出为一个sql文件详细说明 (mysql)

    Datagrip导入导出为一个sql文件详细说明 导出: (我的无法截图, 借用一张) 导入: (我的无法截图, 再借用一张) 完

  7. sass基础—具体编译步骤及对应命令:详细

    /*基础语法*/h1{ color: red;} /*变量定义*/ $color: red; /*嵌套*/body{ header{ } footer{ }} /*mixin函数*/@mixin al ...

  8. js里添加的标签

    js里添加的标签.网页加载此标签绑定的js函数时,由于没有标签,故无法执行函数. 例如: js中添加了一个button: html1 += "<td><button typ ...

  9. Controller中方法返回值其他类型需要添加jackson依赖

    第一个 第二个: 第三个 https://www.cnblogs.com/codejackanapes/p/5569013.html:json的博客园 springmvc默认的是:2.Jackson: ...

  10. 51Nod 1298 圆与三角形(计算几何)

    1298 圆与三角形  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是否相交.相交输出"Yes&quo ...