洛谷 P3004 [USACO10DEC]宝箱Treasure Chest
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.
贝西和伯尼找到了一个装满了金币的宝箱!但是,作为奶牛,他们不能随便进入一家商店去买东西。所以他们决定去用这些金币玩一个游戏。
这里有N(1<=N<=5000)个硬币,每个都有一个价值C_i(1<=C_i<=5000)。这些硬币被摆成了一行。贝西和伯尼每人一回合。到了一只奶牛的回合时,他就要拿走最左边或者最右边的硬币。当没有硬币时,游戏结束。
贝西和伯尼都想要使自己拿到的金币价值尽量高,贝西先拿。现在贝西想要你帮帮她,算出她最多可以拿多少钱(伯尼也会尽量取到最优)。
输入输出格式
输入格式:
Line 1: A single integer: N
- Lines 2..N+1: Line i+1 contains a single integer: C_i
输出格式:
- Line 1: A single integer, which is the greatest total value Bessie can win if both cows play optimally.
输入输出样例
4
30
25
10
35
60
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,w[],s[],f[][];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&w[i]);
s[i]=s[i-]+w[i];
f[i][i]=w[i];
}
for(int i=n;i>=;i--)
for(int j=i+;j<=n;j++)
f[i][j]=max((s[j]-s[i-])-f[i+][j],(s[j]-s[i-])-f[i][j-]);
cout<<f[][n]<<" "<<s[n]-f[][n];
}
洛谷 P3004 [USACO10DEC]宝箱Treasure Chest的更多相关文章
- 洛谷P3004 [USACO10DEC]宝箱Treasure Chest
P3004 [USACO10DEC]宝箱Treasure Chest 题目描述 Bessie and Bonnie have found a treasure chest full of marvel ...
- 洛谷3004 [USACO10DEC]宝箱Treasure Chest
题目:https://www.luogu.org/problemnew/show/P3004 一眼看上去就是记忆化搜索的dp.像 一双木棋 一样. 结果忘了记忆化.T了5个点. 然后加上记忆化.MLE ...
- [LUOGU] P3004 [USACO10DEC]宝箱Treasure Chest
第一眼:区间DP,可以瞎搞 f[i][j]=max(sum(i,j)-f[i+1][j],sum(i,j)-f[i][j-1]) 提出来就是f[i][j]=sum(i,j)-min(f[i+1][j] ...
- [USACO10DEC]宝箱Treasure Chest
区间DP,但是卡空间. n2的就是f[i,j]=sum[i,j]-min(f[i+1][j],f[i][j-1])表示这个区间和减去对手取走的最多的. 但是空间是64MB,就很难受 发现一定是由大区间 ...
- 洛谷 P3003 [USACO10DEC]苹果交货Apple Delivery
洛谷 P3003 [USACO10DEC]苹果交货Apple Delivery 题目描述 Bessie has two crisp red apples to deliver to two of he ...
- 洛谷P3004 宝箱Treasure Chest——DP
题目:https://www.luogu.org/problemnew/show/P3004 似乎有点博弈的意思,但其实是DP: f[i][j] 表示 i~j 的最优结果,就可以进行转移: 注意两个循 ...
- 洛谷P3003 [USACO10DEC]苹果交货Apple Delivery
P3003 [USACO10DEC]苹果交货Apple Delivery 题目描述 Bessie has two crisp red apples to deliver to two of her f ...
- 洛谷——P3003 [USACO10DEC]苹果交货Apple Delivery
P3003 [USACO10DEC]苹果交货Apple Delivery 这题没什么可说的,跑两遍单源最短路就好了 $Spfa$过不了,要使用堆优化的$dijkstra$ 细节:1.必须使用优先队列+ ...
- G - Zombie’s Treasure Chest(动态规划专项)
G - Zombie’s Treasure Chest Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
随机推荐
- go之切片
一.概念 关于切片 1.切片是对数组一个连续片段的引用,所以切片是一个引用类型 2.切片是数组一样可以索引,可以通过len函数获取切片的数据长度.(数组也可以通过len获取) 3.切片是一个长度可变的 ...
- Ubuntu16.04开启root用户,并远程登录
Ubuntu安装完成默认是普通权限的用户,root用户需要手动开启,并且还不含opne-ssh模块 1.给root用户设置密码 # sudo passwd root 会提示输入unix的新密码,这就 ...
- [Luogu2324]八数码难题
抱歉...我可能真的做搜索上瘾了... 还是IDA*,自己看看就好了... 注意一下搜索顺序 #include<cstdio> #include<queue> #include ...
- Blender插件编写指南
前言 Blender插件是Blender的利器, 用户可以使用各种插件扩充Blender的功能. Blender Python插件以bpy.props, bpy.types.Operator, bpy ...
- 使用MALTAB标定实践记录
记录一下整个相机的标定矫正过程,希望能够帮助到刚学习标定的童鞋们- 首先下载matlab calibration toolbox,百度搜索第一条就是了(http://www.vision.caltec ...
- 《CSS Mastery》 读书笔记 (1)
--本笔记中英混合,专业名词尽量不翻译,免得误解,如果不习惯,就不用往下看了,走好不送. 第一章 基础 人类的好奇心总是促使我们捣鼓,捣鼓是最好做有效的学习CSS的方法 In this chapter ...
- 笔记 — 动画效果(Css3)
/** * animation-name: 调用 @keyframes 所定义的动画 * animation-duration: 动画周期所花费的时间长度 * animation-timing-fun ...
- VMWare linux安装mysql 5.7.13
1.基础环境说明 虚拟机:VMWare 操作系统:linux 数据库版本:mysql 5.7.13 社区版(别问为什么不装企业版,因为企业版要钱) 背景:虚拟机可以连上外网 下载目录: /tools/ ...
- 在MFC中使用Cstring
此文介绍了关于MFC使用CString的资料,可一参考一下. 转自于VC知识库:http://www.vckbase.com/index.php/wv/829 通过阅读本文你可以学习如何有效地使用 C ...
- 多开 MFC线程
序言:我才编程几年啊!就要处理多线程.对于只写函数的我,这难度简直了!不过MFC的多线程,貌似比较简单,还能处理的了. (1).开MFC多个线程 在视频采集的过程中,如果不使用媒体计数器,会造成主线程 ...