题意:给一个数组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. tp5 设置layui分页

    \thinkphp\library\think\paginator\driver 添加 Layui.php <?php namespace think\paginator\driver; use ...

  2. 帮你彻底搞懂JS中的prototype、__proto__与constructor(图解)

    作为一名前端工程师,必须搞懂JS中的prototype.__proto__与constructor属性,相信很多初学者对这些属性存在许多困惑,容易把它们混淆,本文旨在帮助大家理清它们之间的关系并彻底搞 ...

  3. Android 应用防止被二次打包指南

    前言 “Android APP二次打包”则是盗版正规Android APP,破解后植入恶意代码重新打包.不管从性能.用户体验.外观它都跟正规APP一模一样但是背后它确悄悄运行着可怕的程序,它会在不知不 ...

  4. oracle 在C# 中调用oracle的数据库时,出现引用库和当前客户端不兼容的问题解决方案

    oracle 在C# 中调用oracle的数据库时,出现引用库和当前客户端不兼容的问题解决方案 解决方案 1.直接引用  Oracle.ManagedDataAccess.Client.dll动态库即 ...

  5. Confluence 6 管理应用服务器内存设置

    应用服务器中的最小和最大 JVM Heap 空间配置将会影响系统的性能.Confluence 管理员可能希望对默认的配置进行修改,基于你系统的负载不同配置情况也会有所不同,请参考页面 Server H ...

  6. Confluence 6 选择一个外部数据库

    注意: 选择一个合适的数据库通常需要花费很多时间.同时 Confluence 自带的 XML 数据备份和恢复功能通常也不适合合并和备份有大量数据的数据库.如果你想在系统运行后进行数据合并,你通常需要使 ...

  7. ios集成极光推送:Undefined symbols for architecture arm64: "_dns_parse_resource_record", referenced from:?

    添加libresolv.tbd库,即可解决问题 Undefined symbols for architecture arm64: "_dns_parse_resource_record&q ...

  8. ionic在ios侧滑页面空白 禁用视图滑动后退

    本人在ios10左右滑动的时候,经常出现左滑页面后退,然后整个页面空白现象,只能强行退出,并重新登录,最简单的方法就是禁用侧滑后退这个功能: 在app.js上config增加如下: $ionicCon ...

  9. LeetCode(92):反转链表 II

    Medium! 题目描述: 反转从位置 m 到 n 的链表.请使用一趟扫描完成反转. 说明:1 ≤ m ≤ n ≤ 链表长度. 示例: 输入: 1->2->3->4->5-&g ...

  10. cf1110F 离线+树上操作+线段树区间更新

    自己搞的算法超时了..但是思路没什么问题:用线段树维护每个点到叶子节点的距离即可 /* 线段树维护区间最小值,每次向下访问,就把访问到的点对应的区间段减去边权 到另一颗子树访问时,向上回溯时加上减去的 ...