POJ2738 Two Ends (DP)
来源:互联网 发布:js中tip 编辑:程序博客网 时间:2024/04/28 07:30
Two Ends
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1811 Accepted: 855
Description
In the two-player game "Two Ends", an even number of cards is laid out in a row. On each card, face up, is written a positive integer. Players take turns removing a card from either end of the row and placing the card in their pile. The player whose cards add up to the highest number wins the game. Now one strategy is to simply pick the card at the end that is the largest -- we'll call this the greedy strategy. However, this is not always optimal, as the following example shows: (The first player would win if she would first pick the 3 instead of the 4.)
3 2 10 4
You are to determine exactly how bad the greedy strategy is for different games when the second player uses it but the first player is free to use any strategy she wishes.
3 2 10 4
You are to determine exactly how bad the greedy strategy is for different games when the second player uses it but the first player is free to use any strategy she wishes.
Input
There will be multiple test cases. Each test case will be contained on one line. Each line will start with an even integer n followed by n positive integers. A value of n = 0 indicates end of input. You may assume that n is no more than 1000. Furthermore, you may assume that the sum of the numbers in the list does not exceed 1,000,000.
Output
For each test case you should print one line of output of the form:
In game m, the greedy strategy might lose by as many as p points.
where m is the number of the game (starting at game 1) and p is the maximum possible difference between the first player's score and second player's score when the second player uses the greedy strategy. When employing the greedy strategy, always take the larger end. If there is a tie, remove the left end.
In game m, the greedy strategy might lose by as many as p points.
where m is the number of the game (starting at game 1) and p is the maximum possible difference between the first player's score and second player's score when the second player uses the greedy strategy. When employing the greedy strategy, always take the larger end. If there is a tie, remove the left end.
Sample Input
4 3 2 10 48 1 2 3 4 5 6 7 88 2 2 1 5 3 8 7 30
Sample Output
In game 1, the greedy strategy might lose by as many as 7 points.In game 2, the greedy strategy might lose by as many as 4 points.In game 3, the greedy strategy might lose by as many as 5 points.
2738Accepted4080K32MSC++1537B
题意是两个人在博弈,一个人用贪心的策略,一个人是理性的,问理性的能够拿到的数最大能比贪心的人拿到的数大多少。初看上去不像是DP,其实仔细想想就可以知道这题是一道DP。隐藏的比较深,找出它的动态方程比较难,分四种情况讨论。开始的时候我只分两种情况讨论了,郁闷了很久。开始的动态方程:
之后想明白了 原来是四种情况,这是之后写的动态方程:
还是贴上代码,大家有什么好的意见,可以和我讨论讨论:
- POJ2738 Two Ends (DP)
- poj2738 Two Ends
- poj 2738 Two Ends 区间dp
- Two Ends
- sicily 1176 Two Ends dp(记忆化搜索)
- POJ 2738 Two Ends(记忆化搜索+dp)
- 1176. Two Ends
- 1176 Two Ends
- 1176. Two Ends
- poj 2738 Two Ends
- soj 1176. Two Ends
- Sicily 1176. Two Ends
- Sicily 1008 two ends
- sicily 1176.Two ends
- [sicily]1176. Two Ends
- 1176. Two Ends
- Sicily 1176. Two Ends
- Sicily 1176. Two Ends
- 读取ini文件的例子(在网上找的)
- 媒体
- 电脑右下角显示你的大名
- CentOS 5.4下安装ORACLE 10g手记
- 外设IO地址空间中的地址怎么转换到内核态的虚拟地址空间(一个ioremap函数真的解释清楚了么)
- POJ2738 Two Ends (DP)
- SQL2005生成序号(行号)表函数
- 4月4日记
- 中国上海与韩国首尔的物价比较
- lost
- 解决 Linux 下mplayer不能显示中文字幕的 问题 !
- Linux下MySQL双向同步复制配置方法
- 基于 HTML5 的 Windows 画图程序
- 前天去图书馆借书 图书馆在开招聘会