BZOJ——2101: [Usaco2010 Dec]Treasure Chest 藏宝箱
http://www.lydsy.com/JudgeOnline/problem.php?id=2101
Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 539  Solved: 294
[Submit][Status][Discuss]
Description
Bessie and Bonnie have found a treasure chest full of marvelous gold coins! Being cows, though, they can't just walk into a store and buy stuff, so instead they decide to have some fun with the coins. The N (1 <= N <= 5,000) coins, each with some value C_i (1 <= C_i <= 5,000) are placed in a straight line. Bessie and Bonnie take turns, and for each cow's turn, she takes exactly one coin off of either the left end or the right end of the line. The game ends when there are no coins left. Bessie and Bonnie are each trying to get as much wealth as possible for themselves. Bessie goes first. Help her figure out the maximum value she can win, assuming that both cows play optimally. Consider a game in which four coins are lined up with these values: 30 25 10 35 Consider this game sequence: Bessie Bonnie New Coin Player Side CoinValue Total Total Line Bessie Right 35 35 0 30 25 10 Bonnie Left 30 35 30 25 10 Bessie Left 25 60 30 10 Bonnie Right 10 60 40 -- This is the best game Bessie can play.
Input
* Line 1: A single integer: N * Lines 2..N+1: Line i+1 contains a single integer: C_i
Output
* Line 1: A single integer, which is the greatest total value Bessie can win if both cows play optimally.
Sample Input
30
25
10
35
Sample Output
HINT
(贝西最好的取法是先取35,然后邦妮会取30,贝西再取25,邦妮最后取10)
Source
区间DP:f[l][r]表示区间[l,r]之间取硬币的最优结果,那么
如果,贝西取在l点,则邦妮去完f[l+1][r],f[l][r]=sum[r]-sum[l-1]-f[l+1][r],贝西取在r同理
#include <cstdio> #define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b) inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
} const int N();
int f[N][N],sum[N];
int n,w[]; int Presist()
{
read(n);
for(int i=; i<=n; ++i)
{
read(w[i]);
f[i][i]=w[i];
sum[i]=sum[i-]+w[i];
}
for(int L=; L<=n; ++L)
for(int r,l=; l<=n-L+; ++l)
{
r=l+L-;
f[l][r]=max(f[l][r],sum[r]-sum[l-]-
min(f[l+][r],f[l][r-]));
}
printf("%d\n",f[][n]);
return ;
} int Aptal=Presist();
int main(int arg,char**argv){;}
二维
该题需要压维、
#include <cstdio> #define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b) inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
} const int N();
int n,f[N],sum[N]; int Presist()
{
read(n);
for(int w,i=; i<=n; ++i)
{
read(w), f[i]=w;
sum[i]=sum[i-]+w;
}
for(int L=; L<n; ++L)
for(int r,l=; l<=n-L; ++l)
f[l]=sum[l+L]-sum[l-]-min(f[l+],f[l]);
printf("%d\n",f[]);
return ;
} int Aptal=Presist();
int main(int arg,char**argv){;}
BZOJ——2101: [Usaco2010 Dec]Treasure Chest 藏宝箱的更多相关文章
- BZOJ 2101: [Usaco2010 Dec]Treasure Chest 藏宝箱( dp )
		
dp( l , r ) = sum( l , r ) - min( dp( l + 1 , r ) , dp( l , r - 1 ) ) 被卡空间....我们可以发现 l > r 是无意义的 ...
 - BZOJ 2101 [Usaco2010 Dec]Treasure Chest 藏宝箱:区间dp 博弈【两种表示方法】【压维】
		
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2101 题意: 共有n枚金币,第i枚金币的价值是w[i]. 把金币排成一条直线,Bessie ...
 - BZOJ 2101: [Usaco2010 Dec]Treasure Chest 藏宝箱(这是我写过最骚气的dp!)
		
题目描述 贝西和邦妮找到了一个藏宝箱,里面都是金币! 但是身为两头牛,她们不能到商店里把金币换成好吃的东西,于是她们只能用这些金币来玩游戏了. 藏宝箱里一共有N枚金币,第i枚金币的价值是Ci.贝西 ...
 - bzoj 2101: [Usaco2010 Dec]Treasure Chest 藏宝箱【区间dp】
		
就是区间dp啦f[i][j]表示以i开头的长为j+1的一段的答案,转移是f[i][j]=s[i+l]-s[i-1]+min(f[i][j-1],f[i+1][j-1]),初始是f[i][1]=a[i] ...
 - 【BZOJ】2101: [Usaco2010 Dec]Treasure Chest 藏宝箱(dp)
		
http://www.lydsy.com/JudgeOnline/problem.php?id=2101 这个dp真是神思想orz 设状态f[i, j]表示i-j先手所拿最大值,注意,是先手 所以转移 ...
 - BZOJ2101: [Usaco2010 Dec]Treasure Chest 藏宝箱
		
2101: [Usaco2010 Dec]Treasure Chest 藏宝箱 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 327 Solved: ...
 - bzoj21012101: [Usaco2010 Dec]Treasure Chest 藏宝箱(滚动数组优化dp)
		
2101: [Usaco2010 Dec]Treasure Chest 藏宝箱 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 592 Solved: ...
 - [Usaco2010 Dec]Treasure Chest 藏宝箱
		
题目链接:点这里 Solution: 刚开始以为是博弈论,然而不是... 首先考虑n方dp,设f(l,r)为只有\(l\)到\(r\)区间的钱的先手最大获利 那么我们可以得到式子f(l,r)=sum( ...
 - bzoj2101【Usaco2010 Dec】Treasure Chest 藏宝箱
		
2101: [Usaco2010 Dec]Treasure Chest 藏宝箱 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 418 Solved: ...
 
随机推荐
- 【linux】文件默认权限:umask
			
在默认权限的属性上,目录与文件是不一样的.从第六章我们知道 x 权限对於目录是非常重要的! 但是一般文件的创建则不应该有运行的权限,因为一般文件通常是用在於数据的记录嘛!当然不需要运行的权限了. 因此 ...
 - 树莓派开发板入门学习笔记2:[转]树莓派系统在VM中能做什么
			
问"树莓派系统在VM中能做什么"不如问"树莓派能做什么":(参考:树莓派实验室) 普通难度的DIY 较高难度的DIY 用树莓派打造一个家庭影院 给树莓派安装摄像 ...
 - Linux入门学习笔记1:VI常用命令
			
常用命令 yy 复制 p 黏贴 shift+v 多行选中 shift+ctrl+< 左移 shift+ctrl+> 右移 ndd 删除光标所在行及其后n-1行 i 进入编辑状态 esc 退 ...
 - 线段树:POJ3468-A Simple Problem with Integers(线段树注意事项)
			
A Simple Problem with Integers Time Limit: 10000MS Memory Limit: 65536K Description You have N integ ...
 - selenium2-元素管理方式及解析
			
1.管理文件格式:yaml 2.Yaml里面的内容格式: 3.格式说明: baidu_input后面接上":",直接回车,然后空两格 type与value这两个key是固定 ...
 - HDU 4965 Fast Matrix Calculation 矩阵快速幂
			
题意: 给出一个\(n \times k\)的矩阵\(A\)和一个\(k \times n\)的矩阵\(B\),其中\(4 \leq N \leq 1000, \, 2 \leq K \leq 6\) ...
 - js 判断ie的版本号
			
//IE6判断: var isIE6 = !!window.ActiveXObject && !window.XMLHttpRequest; //或者: if(navigator.us ...
 - 《Effective Java》笔记 :(一)创建和销毁对象
			
一 .考虑用静态工厂方法代替构造器 1. 静态工厂方法与设计模式中的工厂方法模式不同,注意不要混淆 例子: public static Boolean valueOf(boolean b){ retu ...
 - JS使用onerror进行默认图像显示,可代替alt
			
JS代码 //图像加载出错时的处理 function errorImg(img) { img.src = "默认图片.jpg"; img.onerror = null; } HTM ...
 - Django模板导入和替换、以及对数据库的增加、查看
			
静态文件引入的3中方式:例如对html模板里面对css样式的引入 STATIC_URL = '/static666/'STATICFILES_DIR=[ os.path.join(BASE_DIR,' ...