bzoj2101【Usaco2010 Dec】Treasure Chest 藏宝箱
来源:互联网 发布:兄弟绣花机软件 编辑:程序博客网 时间:2024/05/17 06:21
2101: [Usaco2010 Dec]Treasure Chest 藏宝箱
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 418 Solved: 206
[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
Silver
动态规划的空间优化,感觉方法还是不错的。
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#define F(i,j,n) for(int i=j;i<=n;i++)#define D(i,j,n) for(int i=j;i>=n;i--)#define ll long long#define maxn 5005using namespace std;int n,x;int f[maxn],sum[maxn];inline int read(){int x=0,f=1;char ch=getchar();while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}int main(){n=read();sum[0]=0;F(i,1,n){x=read();sum[i]=sum[i-1]+x;f[i]=x;}F(j,1,n-1) F(i,1,n-j) f[i]=sum[i+j]-sum[i-1]-min(f[i],f[i+1]);printf("%d\n",f[1]);}
- bzoj2101【Usaco2010 Dec】Treasure Chest 藏宝箱
- BZOJ2101: [Usaco2010 Dec]Treasure Chest 藏宝箱
- BZOJ2101: [Usaco2010 Dec]Treasure Chest 藏宝箱
- bzoj2101[Usaco2010 Dec]Treasure Chest 藏宝箱 DP
- 【bzoj2101】[Usaco2010 Dec]Treasure Chest 藏宝箱
- Usaco2010 Dec Treasure Chest
- Usaco2010 Dec Treasure Chest
- BZOJ 2101: [Usaco2010 Dec]Treasure Chest 藏宝箱
- USACO2010 December Treasure Chest & POI2010 The Minima Game
- USACO 2010 Dec Silver 2.Treasure Chest 简单博弈 DP
- hdu4901Zombie’s Treasure Chest
- HDU4091 Zombie’s Treasure Chest
- hdu4091 Zombie’s Treasure Chest
- UVa12325 - Zombie's Treasure Chest
- 12325 Zombie's Treasure Chest
- 12325 - Zombie's Treasure Chest.
- 12325 - Zombie's Treasure Chest
- Zombie's Treasure Chest UVA
- bzoj2023【Usaco2005 Nov】Ant Counting 数蚂蚁
- 最优化的几个问题的解法和比较之——无约束的非线性规划
- 俄罗斯程序员的编程人生
- HTML5移动开发实战必备知识——本地存储(1)
- SSH错误
- bzoj2101【Usaco2010 Dec】Treasure Chest 藏宝箱
- eclipse4.5在Linux下标题栏显示过大的调整方法
- bzoj1710【Usaco2007 Open】Cheappal 廉价回文
- usaco 第一章博客指引
- 关于Gson的各数据类型转换
- 实现卡片翻转的动画效果
- mysql阅读笔记六
- LeetCode题解:Reverse Linked List
- 51nod 1092 回文字符串 dp问题