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

隨筆 - 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ⅴ| 亚洲黄色小视频| 久久久久久国产精品一区| 国产精品毛片高清在线完整版| 国产主播在线一区| 亚洲欧美日韩在线不卡| 91久久在线播放| 另类综合日韩欧美亚洲| 国产精品一卡二卡| 亚洲视频日本| 亚洲国产美女| 免费观看欧美在线视频的网站| 国产亚洲精品v| 亚洲女同精品视频| 日韩午夜电影在线观看| 欧美国产一区视频在线观看| 在线播放国产一区中文字幕剧情欧美| 欧美一区国产在线| 亚洲一级影院| 国产精品高潮在线| 亚洲视频在线二区| 亚洲免费福利视频| 最新热久久免费视频| 久久大综合网| 亚洲午夜久久久久久尤物| 欧美日韩免费网站| 亚洲精品资源| 亚洲国产清纯| 欧美国产精品劲爆| 亚洲精品少妇| 日韩视频二区| 国产精品久久久久毛片大屁完整版 | 亚洲视频免费看| 国产精品黄视频| 久久av二区| 久久乐国产精品| 亚洲国产你懂的| 亚洲成人在线网站| 欧美国产精品中文字幕| 一区二区三区色| 亚洲无线视频| 国产日韩欧美精品| 免费不卡在线观看| 欧美电影在线观看| 亚洲一区二区免费| 亚洲欧美日韩直播| 亚洲高清二区| 日韩视频亚洲视频| 国产日韩欧美综合| 亚洲第一精品影视| 欧美日韩免费在线| 欧美在线观看视频| 美女主播一区| 新67194成人永久网站| 久久xxxx| 亚洲久久在线| 这里是久久伊人| 国产一区二区三区四区三区四| 女仆av观看一区| 欧美日韩在线视频首页| 久久精品99国产精品日本| 免费高清在线一区| 亚洲午夜精品国产| 欧美一级片一区| 99re6这里只有精品| 亚洲欧美日韩一区二区三区在线观看| 亚洲第一搞黄网站| 亚洲免费视频一区二区| 亚洲精品一区二区三区不| 性久久久久久| 亚洲午夜在线视频| 农夫在线精品视频免费观看| 午夜欧美大片免费观看| 欧美大成色www永久网站婷| 久久国产精品久久久久久久久久| 欧美77777| 久久久久这里只有精品| 欧美日韩中文字幕日韩欧美| 久久伊人免费视频| 国产精品日本精品| 亚洲精品在线观看免费| 亚洲电影免费| 久久国产加勒比精品无码| 亚洲欧美日韩高清| 亚洲已满18点击进入久久| 久热精品视频在线观看| 午夜欧美不卡精品aaaaa| 欧美久久成人| 欧美国产日韩a欧美在线观看| 国产婷婷成人久久av免费高清| 日韩午夜在线播放| 91久久黄色| 久久中文字幕导航| 久久久久久成人| 国产精品永久| 亚洲欧美成人| 性色av一区二区三区红粉影视| 欧美日韩在线播放三区| 亚洲精品免费网站| 最新国产乱人伦偷精品免费网站 | 麻豆精品在线观看| 国产一区二区精品久久| 亚洲欧美激情在线视频| 午夜国产精品视频| 国产精品美女在线| 亚洲欧美韩国| 欧美高清视频一区二区| 久久精品国产亚洲aⅴ| 国产精品美女久久久久久久| 一区二区三区导航| 亚洲欧美日本国产有色| 欧美视频手机在线| 亚洲视频 欧洲视频| 欧美一级夜夜爽| 国产一区二区三区四区三区四| 亚洲欧洲美洲综合色网| 免费不卡在线视频| 亚洲精品国产视频| 亚洲午夜女主播在线直播| 欧美吻胸吃奶大尺度电影| 亚洲视频免费| 久久久久国产精品一区| 伊人久久av导航| 欧美黑人在线观看| 一区二区三区不卡视频在线观看 | 欧美视频一区二区三区| 亚洲一区二区在线免费观看| 久久久久久久久伊人| 亚洲激情女人| 欧美日韩一区二区精品| 午夜精品免费在线| 欧美成年人视频| 一区二区三区欧美日韩| 国产精品久久久久久妇女6080 | 国产精品白丝jk黑袜喷水| 亚洲一区二区三区国产| 农村妇女精品| 亚洲欧美激情一区| 在线一区免费观看| 美女国产一区| 中文精品视频一区二区在线观看| 国产中文一区| 亚洲视频一区二区免费在线观看| 欧美粗暴jizz性欧美20| 亚洲国产精品久久人人爱蜜臀| 国产亚洲欧美aaaa| 久久久久久九九九九| 亚洲影院在线| 久久视频免费观看| 久久精品国产欧美亚洲人人爽| 欧美午夜性色大片在线观看| 欧美a级一区| 在线日韩中文字幕| 欧美一区日本一区韩国一区| 久久精品视频在线看| 国产精品yjizz| 午夜精品久久久久久99热软件| 国产日韩欧美一区在线| 亚洲欧美国产毛片在线| 亚洲欧美日韩综合aⅴ视频| 好吊视频一区二区三区四区| 欧美—级a级欧美特级ar全黄| 欧美亚洲免费在线| 在线亚洲欧美| 日韩亚洲视频在线| 亚洲激情专区| 久久久xxx|