POJ3086 Treats for the Cows(区间DP)
题目链接 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)的更多相关文章
- POJ3186:Treats for the Cows(区间DP)
Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...
- 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 ...
- Treats for the Cows 区间DP POJ 3186
题目来源:http://poj.org/problem?id=3186 (http://www.fjutacm.com/Problem.jsp?pid=1389) /** 题目意思: 约翰经常给产奶量 ...
- 【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或者 ...
- poj3186 Treats for the Cows(区间)
题目链接:http://poj.org/problem?id=3186 题意:第一个数是N,接下来N个数,每次只能从队列的首或者尾取出元素. ans=每次取出的值*出列的序号.求ans的最大值. 样例 ...
- POJ 3186Treats for the Cows(区间DP)
题目链接:http://poj.org/problem?id=3186 题目大意:给出的一系列的数字,可以看成一个双向队列,每次只能从队首或者队尾出队,第n个出队就拿这个数乘以n,最后将和加起来,求最 ...
- POJ 3186Treats for the Cows (区间DP)
详见代码 #include <stdio.h> #include <algorithm> #include <string.h> using namespace s ...
- [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[ ...
- POJ 3186 Treats for the Cows ——(DP)
第一眼感觉是贪心,,果断WA.然后又设计了一个两个方向的dp方法,虽然觉得有点不对,但是过了样例,交了一发,还是WA,不知道为什么不对= =,感觉是dp的挺有道理的,,代码如下(WA的): #incl ...
随机推荐
- 笔记-python-build-in-types
笔记-python-build-in-types 注:文档内容来源为Python 3.6.5 documentation 1. built-in types 1.1. 真值测试 所有对 ...
- Redis实现之对象(一)
对象 前面我们介绍了Redis的主要数据结构,如:简单动态字符串SDS.双端链表.字典.压缩列表.整数集合等.Redis并没有直接使用这些数据结构来实现键值对数据库,而是基于这些数据结构创建了一个对象 ...
- 递归查询子类sql
--通过父节点查询子节点 WITH TREE AS( SELECT * FROM Role WHERE RoleID = 4 -- 要查询的父 id UNION ALL SELECT Role.* F ...
- 12 JVM 垃圾回收(下)
Java 虚拟机的堆划分 Java 虚拟机将堆划分为新生代和老年代.其中新生代又被划分为 Eden 区,以及两个大小相同的 Survivor 区. 默认情况下,Java 虚拟机采取一种动态分配的策略, ...
- LeetCode with Python -> Linked List
21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list s ...
- Zookeeper 增删改查
初始化对象连接到zookeeper服务: public ZooKeeper initZk(){ final CountDownLatch countDownLatch = new CountDownL ...
- File IO(NIO.2):读、写并创建文件
简介 本页讨论读,写,创建和打开文件的细节.有各种各样的文件I / O方法可供选择.为了帮助理解API,下图以复杂性排列文件I / O方法 在图的最左侧是实用程序方法readAllBytes,read ...
- Linux系统基础优化总结
请称呼我搬运工,哈哈 优化综合 https://www.cnblogs.com/yinshoucheng-golden/p/6149556.html (1)不用root管理,以普通用户的名义通过sud ...
- linux系统ssh远程连接检查脚本
脚本用于检查Linux系统云服务器出现的常见远程不能连接问题,脚本可以提前放到服务器里,出现问题时可以web vnc登陆上去执行试试. 附:管理控制台终端web vnc 方式登录,参考:http:// ...
- LAMP第一部分安装mysql -apache -php
1. 安装mysqlcd /usr/local/src/ 免安装编译二进制的包wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-l ...