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

隨筆 - 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>
            亚洲天堂成人| 欧美片在线观看| 亚洲一二三四久久| 毛片一区二区三区| 久久精品在线| 国产精品美女诱惑| 亚洲精品小视频在线观看| 亚洲国产精彩中文乱码av在线播放| 亚洲欧美国产另类| 亚洲欧美日韩综合aⅴ视频| 欧美日韩国产亚洲一区| 亚洲电影专区| 亚洲级视频在线观看免费1级| 久久精品国产亚洲a| 久久九九精品99国产精品| 国产午夜精品理论片a级大结局 | 亚洲第一黄网| 久久国产精品72免费观看| 久久精品夜夜夜夜久久| 国产视频久久| 久久爱另类一区二区小说| 久久久999成人| 激情久久久久| 美女尤物久久精品| 亚洲激情黄色| 一区二区三区视频在线观看| 欧美日韩一区免费| 亚洲一区精彩视频| 久久久久久久久久久久久久一区| 国产午夜精品美女视频明星a级 | 亚洲日本va午夜在线影院| 欧美成人午夜剧场免费观看| 亚洲欧洲一区二区在线播放| 亚洲图片在区色| 国产精品乱子久久久久| 欧美一级免费视频| 噜噜噜噜噜久久久久久91| 亚洲国产欧美精品| 欧美日韩免费观看中文| 亚洲欧美日韩国产综合| 久久久欧美精品| 亚洲日本一区二区三区| 欧美三级欧美一级| 先锋a资源在线看亚洲| 欧美xart系列高清| 在线亚洲激情| 黑人一区二区三区四区五区| 美女精品在线观看| 宅男噜噜噜66国产日韩在线观看| 久久精品综合一区| 亚洲精品视频免费观看| 国产精品免费aⅴ片在线观看| 久久国产精品毛片| 亚洲精品视频一区二区三区| 久久福利一区| 亚洲精品免费网站| 国产乱码精品一区二区三区忘忧草| 久久精品视频在线看| 亚洲乱码久久| 久久久久久有精品国产| 99riav国产精品| 国产在线国偷精品产拍免费yy| 欧美va天堂在线| 香蕉成人伊视频在线观看| 亚洲国产日韩在线| 久久久另类综合| 亚洲欧美国产视频| 亚洲激情第一区| 国产日韩欧美在线一区| 欧美日韩三级| 久久阴道视频| 性久久久久久久久久久久| 日韩视频一区二区三区| 美国成人毛片| 久久九九精品| 先锋影音国产一区| 亚洲私人影院| 99成人在线| 91久久视频| 在线成人欧美| 狠狠久久五月精品中文字幕| 国产精品久久午夜| 欧美日本精品在线| 免费一级欧美在线大片| 久久久精品欧美丰满| 亚洲欧美卡通另类91av| aⅴ色国产欧美| 亚洲精品在线观| 亚洲激情中文1区| 欧美国产日韩精品| 欧美a级大片| 久久综合久久综合这里只有精品| 午夜亚洲福利| 性欧美大战久久久久久久免费观看| 日韩一区二区精品葵司在线| 亚洲黄一区二区| 亚洲精品在线观看免费| 亚洲日本激情| 日韩视频精品在线| 日韩视频三区| 一区二区三区毛片| 亚洲午夜精品久久久久久app| 日韩天堂av| 一区二区三区鲁丝不卡| 亚洲视频香蕉人妖| 亚洲欧美日本在线| 新67194成人永久网站| 亚洲综合清纯丝袜自拍| 性欧美18~19sex高清播放| 亚洲欧美一区二区精品久久久| 亚洲一区在线观看免费观看电影高清 | 国产一区二区三区精品久久久| 国产欧美一区二区三区在线老狼 | 先锋影院在线亚洲| 欧美亚洲一级| 久久综合国产精品| 久久亚洲精品欧美| 免费欧美视频| 亚洲国产乱码最新视频| 亚洲精品小视频| 亚洲一区二区三区四区中文| 欧美一区二区三区在| 久久免费视频网| 欧美日本免费一区二区三区| 欧美性片在线观看| 国产一区导航| 亚洲欧洲另类国产综合| 亚洲一区二区精品| 久久久女女女女999久久| 欧美激情亚洲国产| 中文一区二区| 久久在线观看视频| 欧美日韩影院| 一区二区三区在线看| 99av国产精品欲麻豆| 欧美在线视频播放| 亚洲国产第一页| 亚洲一区二区在线播放| 久久女同精品一区二区| 欧美日韩午夜剧场| 欧美亚洲免费| 欧美经典一区二区三区| 欧美一区在线看| 欧美成人激情在线| 性欧美大战久久久久久久免费观看| 国际精品欧美精品| 亚洲精品乱码久久久久久黑人| 午夜精品一区二区三区电影天堂| 麻豆精品视频在线观看| 国产精品99久久久久久人| 久久久久.com| 国产精品一区久久久久| 亚洲精一区二区三区| 久久久久国产精品人| 亚洲精品综合精品自拍| 久久亚洲精品网站| 国产伦精品免费视频| 99精品国产高清一区二区| 老色鬼精品视频在线观看播放| 亚洲午夜三级在线| 欧美韩日一区二区三区| 激情五月婷婷综合| 欧美一区91| 亚洲图片欧美午夜| 欧美日韩精品在线播放| 亚洲国产欧美日韩精品| 久久亚洲国产精品日日av夜夜| 亚洲一区二区三区中文字幕在线| 欧美国产国产综合| 亚洲高清不卡| 欧美v亚洲v综合ⅴ国产v| 午夜久久福利| 国产欧美精品久久| 亚洲欧美日韩久久精品| 一本一本大道香蕉久在线精品| 欧美二区乱c少妇| 亚洲国产精品一区二区www在线| 久久亚洲国产精品一区二区| 午夜精品久久久久久| 国产精品无码永久免费888| 一本色道久久综合亚洲精品不卡| 欧美激情一区二区| 蜜臀久久99精品久久久久久9 | 国产偷国产偷精品高清尤物| 亚洲中字黄色| 亚洲一区视频| 国产精品稀缺呦系列在线| 亚洲欧美视频在线观看视频| 夜夜夜精品看看| 国产精品第一页第二页第三页| 亚洲无吗在线| 亚洲视频中文| 国产欧美在线观看| 久久久久中文| 久热精品视频在线| 99国产精品久久久久久久久久| 亚洲精品日本| 国产精品久线观看视频| 久久黄色小说| 鲁大师成人一区二区三区|