青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 87  文章 - 279  trackbacks - 0
<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

潛心看書研究!

常用鏈接

留言簿(19)

隨筆分類(81)

文章分類(89)

相冊

ACM OJ

My friends

搜索

  •  

積分與排名

  • 積分 - 219404
  • 排名 - 118

最新評論

閱讀排行榜

評論排行榜

Two Ends
Time Limit:1000MS? Memory Limit:65536K
Total Submit:625 Accepted:271

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.

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.

Sample Input

4 3 2 10 4
8 1 2 3 4 5 6 7 8
8 2 2 1 5 3 8 7 3
0

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.

Source
East Central North America 2005

#include? < iostream >
#include?
< cmath >
using ? namespace ?std;

const ? int ?MAXN? = ? 1001 ;
int ?dp[MAXN][MAXN];

int ?main()
{
????
int ?i,?j,?l,?n;
????
int ?t? = ? 1 ;
????
int ?tmp;
????
int ?a[MAXN];
????
while ?(scanf( " %d " ,? & n),?n > 0 )
????
{
????????memset(dp,?
0 ,? sizeof (dp));
????????
for ?(i = 1 ;?i <= n;?i ++ )
????????????scanf(
" %d " ,? & a[i]);
????????????
????????
for ?(i = 1 ;?i < n;?i ++ )
????????????dp[i][i
+ 1 ]? = ?abs(a[i]? - ?a[i + 1 ]);
????????
for ?(l = 4 ;?l <= n;?l += 2 )
????????
{
????????????
for ?(i = 1 ;?i <= n - l + 1 ;?i ++ )
????????????
{
????????????????j?
= ?i? + ?l? - ? 1 ;
????????????????
if ?(a[j]? <= ?a[i + 1 ])
????????????????
{
????????????????????tmp?
= ?dp[i + 2 ][j]? + ?a[i]? - ?a[i + 1 ];
????????????????????
if ?(dp[i][j]? < ?tmp)
????????????????????????dp[i][j]?
= ?tmp;
????????????????}

????????????????
if ?(a[i]? < ?a[j - 1 ])
????????????????
{
????????????????????tmp?
= ?dp[i][j - 2 ]? + ?a[j]? - ?a[j - 1 ];
????????????????????
if ?(dp[i][j]? < ?tmp)
????????????????????????dp[i][j]?
= ?tmp;
????????????????}

????????????????
if ?(a[i]? >= ?a[j - 1 ])
????????????????
{
????????????????????tmp?
= ?dp[i + 1 ][j - 1 ]? + ?a[j]? - ?a[i];
????????????????????
if ?(dp[i][j]? < ?tmp)
????????????????????????dp[i][j]?
= ?tmp;
????????????????}

????????????????
if ?(a[j]? > ?a[i + 1 ])
????????????????
{
????????????????????tmp?
= ?dp[i + 1 ][j - 1 ]? + ?a[i]? - ?a[j];
????????????????????
if ?(dp[i][j]? < ?tmp)
????????????????????????dp[i][j]?
= ?tmp;
????????????????}

????????????}

????????}

????????printf(
" In?game?%d,?the?greedy?strategy?might?lose?by?as?many?as?%d?points.\n " ,?t ++ ,?dp[ 1 ][n]);
????}

????system(
" pause " );
????
return ? 0 ;
}

posted on 2006-08-28 16:00 閱讀(579) 評論(0)  編輯 收藏 引用 所屬分類: ACM題目
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            中国成人在线视频| 亚洲激情成人在线| 久久国产毛片| 久久se精品一区二区| 99re8这里有精品热视频免费 | 亚洲欧美日韩视频一区| 亚洲午夜激情在线| 国产一区二区三区自拍| 欧美国产另类| 欧美日韩精品久久| 欧美在线一区二区| 蜜臀av一级做a爰片久久| 一本色道婷婷久久欧美| 亚洲专区在线| 在线精品观看| 亚洲一二三四区| 亚洲成人在线网| 日韩网站在线观看| 国内揄拍国内精品久久| 亚洲国产欧美日韩另类综合| 国产精品国产三级国产aⅴ入口| 久久精品一区二区三区不卡| 你懂的国产精品永久在线| 亚洲影视在线| 老司机免费视频一区二区三区| 亚洲视频精品| 久久青草福利网站| 午夜亚洲性色福利视频| 开心色5月久久精品| 羞羞答答国产精品www一本 | 午夜国产精品影院在线观看| 亚洲人被黑人高潮完整版| 亚洲尤物视频在线| 一区二区不卡在线视频 午夜欧美不卡在 | 99精品国产99久久久久久福利| 亚洲桃花岛网站| 亚洲精品乱码| 久久精品国产久精国产爱| 亚洲欧美日韩精品久久久| 欧美大色视频| 欧美不卡三区| 国产亚洲欧美一区二区三区| 正在播放日韩| 宅男精品导航| 欧美久久精品午夜青青大伊人| 久久亚洲国产成人| 国产欧美日本一区二区三区| 一区二区欧美在线| 一本色道久久88亚洲综合88| 另类图片综合电影| 猛男gaygay欧美视频| 国产一区二区| 欧美一区二区视频在线观看| 性欧美xxxx视频在线观看| 欧美少妇一区二区| 99热在线精品观看| 一本色道久久99精品综合| 欧美国产一区二区在线观看 | 欧美在线日韩精品| 国产精品激情| 欧美大学生性色视频| 免费一区二区三区| 国内精品久久久| 性欧美xxxx视频在线观看| 校园春色综合网| 国产精品一区二区欧美| 性18欧美另类| 久久综合狠狠| 亚洲国产高清视频| 欧美黄色免费网站| 日韩视频免费在线观看| 亚洲欧美日韩一区二区| 国产美女搞久久| 久久精品理论片| 欧美成人一二三| 99国产精品99久久久久久| 欧美屁股在线| 亚洲免费在线看| 久久色在线观看| 亚洲激情啪啪| 国产精品国色综合久久| 欧美一区二区三区喷汁尤物| 欧美电影在线观看完整版| 亚洲精品影院在线观看| 国产精品成人观看视频国产奇米| 亚洲欧美三级伦理| 欧美激情中文字幕一区二区| 亚洲视频中文| 黑人极品videos精品欧美裸| 欧美激情按摩| 午夜久久久久久| 亚洲欧洲另类| 欧美一区二区三区四区在线观看地址| 国模吧视频一区| 欧美日韩伦理在线免费| 新67194成人永久网站| 亚洲国产精品成人va在线观看| 亚洲综合不卡| 亚洲第一成人在线| 国产精品日韩欧美一区| 久久综合狠狠综合久久激情| 一区二区三区黄色| 欧美刺激性大交免费视频| 亚洲在线免费观看| 亚洲国产精品欧美一二99| 国产精品系列在线| 欧美激情1区| 久久久91精品国产| 亚洲制服丝袜在线| 最新69国产成人精品视频免费| 久久久久综合网| 亚洲嫩草精品久久| 日韩午夜精品视频| 在线观看日韩国产| 国产日产欧美a一级在线| 欧美日本国产在线| 欧美a级大片| 久久久夜夜夜| 久久成人精品无人区| 亚洲综合第一页| 99天天综合性| 亚洲精品久久久久中文字幕欢迎你| 久久免费精品视频| 欧美亚洲免费电影| 亚洲一区二区日本| 在线亚洲激情| 一区二区高清在线观看| 亚洲精品一区二| 亚洲人体大胆视频| 在线观看日韩www视频免费 | 蜜桃av一区| 久久久久久夜| 久久国产欧美日韩精品| 一区二区三区四区五区视频| 亚洲精品一二三| 亚洲精选中文字幕| 99国产精品99久久久久久| 亚洲日本一区二区| 99精品99| 亚洲在线黄色| 欧美在线短视频| 久久久五月婷婷| 美日韩在线观看| 欧美.www| 亚洲国产经典视频| 亚洲三级电影在线观看| 99爱精品视频| 亚洲免费人成在线视频观看| 亚洲一区亚洲| 久久久成人精品| 久久综合激情| 欧美日韩国产a| 国产精品欧美一区二区三区奶水 | 亚洲卡通欧美制服中文| 日韩视频永久免费| 亚洲影院免费| 久久激情综合| 欧美成熟视频| 9色精品在线| 亚洲欧美三级在线| 蜜臀a∨国产成人精品| 欧美日韩国产精品专区| 国产精品一卡二卡| 亚洲福利av| 亚洲天堂男人| 久久久午夜电影| 亚洲精品免费在线播放| 午夜国产欧美理论在线播放| 久久精品主播| 欧美日韩一区二区国产| 国产乱码精品一区二区三区av| 狠狠色伊人亚洲综合网站色| 99精品国产在热久久下载| 午夜亚洲精品| 亚洲国产合集| 欧美在线视频在线播放完整版免费观看| 理论片一区二区在线| 国产精品高清网站| 亚洲国产精品va在线看黑人| 亚洲一区二区黄| 欧美超级免费视 在线| 亚洲天堂成人在线观看| 欧美成人午夜视频| 国产一区二区三区自拍| 99国产成+人+综合+亚洲欧美| 久久久国产视频91| 一区二区欧美日韩| 欧美成人激情视频免费观看| 国产欧美精品日韩精品| 一区二区三区 在线观看视频| 久久久午夜电影| 亚洲欧美电影在线观看| 欧美精品在线观看91| 亚洲高清视频一区二区| 欧美一区2区视频在线观看| 亚洲另类在线视频| 欧美mv日韩mv国产网站| 国语对白精品一区二区| 欧美一区二区久久久| 99国内精品久久|