题目链接  Treats for the Cows

直接区间DP就好了,用记忆化搜索是很方便的。

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define rep(i,a,b) for(int i(a); i <= (b); ++i)
#define LL long long const int Q = + ; LL f[Q][Q];
LL a[Q];
int n;
int s[Q];
int c[Q][Q]; LL dp(int i, int j, LL k){
if (i == j) return a[i] * k;
if (f[i][j] != -) return f[i][j];
LL ret = -100000000000LL;
ret = max(ret, a[i] * k + dp(i + , j, k + ));
ret = max(ret, a[j] * k + dp(i, j - , k + ));
return f[i][j] = ret;
} int main(){ while(~scanf("%d", &n)){
rep(i, , n) scanf("%lld", a + i);
memset(f, -, sizeof f);
printf("%lld\n", dp(, n, 1LL));
} return ; }

POJ3086 Treats for the Cows(区间DP)的更多相关文章

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

  3. Treats for the Cows 区间DP POJ 3186

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

  4. 【BZOJ】1652: [Usaco2006 Feb]Treats for the Cows(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1652 dp.. 我们按间隔的时间分状态k,分别为1-n天 那么每对间隔为k的i和j.而我们假设i或者 ...

  5. poj3186 Treats for the Cows(区间)

    题目链接:http://poj.org/problem?id=3186 题意:第一个数是N,接下来N个数,每次只能从队列的首或者尾取出元素. ans=每次取出的值*出列的序号.求ans的最大值. 样例 ...

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

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

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

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

  8. [luoguP2858] [USACO06FEB]奶牛零食Treats for the Cows(DP)

    传送门 f[i][j][k] 表示 左右两段取到 i .... j 时,取 k 次的最优解 可以优化 k 其实等于 n - j + i 则 f[i][j] = max(f[i + 1][j] + a[ ...

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

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

随机推荐

  1. HDU 3896 Greatest TC 双连通分量

    题意 给一个连通的无向图,有两种询问: \(a, b, c, d\),问如果删掉\(c,d\)之间的边,\(a,b\)之间是否还连通 \(a, b, c\),问如果删掉顶点\(c\),\(a,b\)之 ...

  2. [转]using components in Cakephp 2+ Shell

    <?php App::uses('AppShell', 'Console/Command'); App::uses('ComponentCollection', 'Controller'); A ...

  3. Understanding on 'Error to Origin (50x)' , 'Internal CDN Error (50x)' and 'External Error (50x)' in Chartron

    Overview This document explains about definition of these values on OUI Chartron. Definition of Erro ...

  4. 设计模式之第6章-迭代器模式(Java实现)

    设计模式之第6章-迭代器模式(Java实现) “我已经过时了,就不要讲了吧,现在java自带有迭代器,还有什么好讲的呢?”“虽然已经有了,但是具体细节呢?知道实现机理岂不美哉?”“好吧好吧.”(迭代器 ...

  5. 纯js国际化(i18n)

    i18n,是internationalization单词的简写,中间18个字符略去,简称i18n,意图就是实现国际化,方便产品在不同的场景下使用 目标:可以点击切换语言或者ChangeLanguage ...

  6. python - 接口自动化测试 - GetLog - 日志类封装

    # -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: get_logger.py @ide: PyCharm C ...

  7. [错误处理]AttributeError: 'generator' object has no attribute 'next'

    在python3下学习yield用法. 程序如下: def bar(n): m = n while True: m += 1 yield m b = bar(3) print(b.next()) 程序 ...

  8. leetcode NO.53 最大子序列和 (python实现)

    来源 https://leetcode-cn.com/problems/maximum-subarray/description/ 题目描述 给出一个 32 位的有符号整数,你需要将这个整数中每位上的 ...

  9. poj3083 Children of the Candy Corn BFS&&DFS

    Children of the Candy Corn Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11215   Acce ...

  10. 多IP指定出口IP地址 如何指定云服务器源IP?

    如果一个主机绑定有多个IP地址,那么在被动响应和主动发起连接两种方式中,源IP地址的选择机制肯定是有所差异的.主机在接收外部数据包,并发送响应数据包时,响应源地址显然就是客户端请求的地址,这是非常容易 ...