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 ...
随机推荐
- 二分答案:Poweroj2461-入门基础之二分答案(二分法的应用)
传送门:点击打开链接 入门基础之二分答案 Time Limit: 1000 MS Memory Limit: 65536 KBTotal Submit: 179 Accepted: 33 Page V ...
- [BZOJ1208]宠物收养所(Splay)
Description 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物.每个领养者都希望领养到自己满意的宠物,阿Q根据领养者的要求通过他自己发明的一个特 ...
- Python 内置函数isinstance
isinstance 用来判断对象的类型 isinstance(对象,类型/类型集合) 如果属于 返回True 不属于返回 False >>> a = 1 >>> ...
- This application has request the Runtime to terminate it in an unusual way.
Q: CertsMV.exe gui popup two dialogs as follow. A: 测试发现是分配内存导致,频繁分配内存(大约6M) 可能是堆管理导致 分配大内存分配失败,程序未对 ...
- Azure Active Directory Connect是如何协助管理员工作的?
TechTarget中国原创] 应用基于云的Microsoft Azure Active Directory,管理员们可以将本地Active Directory整合到Windows Server中.通 ...
- C#入门篇6-3:字符串操作 string的ToString() Split()和Copy()方法
//ToString()方法 public static void OutPut() { //字符型转换 转为字符串 Console.WriteLine(.ToString("n" ...
- 57、android 应用内全局通知的实现方法
1.后台运行一个服务 间隔5s从服务器获取一次数据,根据业务需要,当需要提醒给用户时,从右侧自动划出 类似效果如下:在任何界面都会有通知弹窗 2.实现过程 ①android的根布局叫dector( ...
- Android坐标getLeft,getRight,getTop,getBottom,getLocationInWindow和getLocationOnScreen
Android中获取坐标点的一些方法解释 一.getLocationInWindow和getLocationOnScreen的区别 // location [0]--->x坐标,location ...
- LeetCode with Python -> String
344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...
- stdlib.h中自带的两个算法qsort,bsearch
http://zh.cppreference.com/w/c/algorithm ========== void qsort( void *ptr, size_t count, size_t size ...