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

隨筆 - 87  文章 - 279  trackbacks - 0
<2006年3月>
2627281234
567891011
12131415161718
19202122232425
2627282930311
2345678

潛心看書研究!

常用鏈接

留言簿(19)

隨筆分類(81)

文章分類(89)

相冊

ACM OJ

My friends

搜索

  •  

積分與排名

  • 積分 - 220433
  • 排名 - 118

最新評論

閱讀排行榜

評論排行榜

Spiderman’s workout
Time Limit:1000MS? Memory Limit:65536K
Total Submit:211 Accepted:63 Special Judged

Description
Staying fit is important for every super hero, and Spiderman is no exception. Every day he undertakes a climbing exercise in which he climbs a certain distance, rests for a minute, then climbs again, rests again, and so on. The exercise is described by a sequence of distances d1, d2, . . . , dm telling how many meters he is to climb before the first first break, before the second break, and so on. Froman exercise perspective it does not really matter if he climbs up or down at the i:th climbing stage, but it is practical to sometimes climb up and sometimes climb down so that he both starts and finishes at street level. Obviously, he can never be below street level. Also, he would like to use as low a building as possible (he does not like to admit it, but he is actually afraid of heights). The building must be at least 2 meters higher than the highest point his feet reach during the workout.

He wants your help in determining when he should go up and when he should go down. The answer must be legal: it must start and end at street level (0 meters above ground) and it may never go below street level. Among the legal solutions he wants one that minimizes the required building height. When looking for a solution, you may not reorder the distances.

If the distances are 20 20 20 20 he can either climb up, up, down, down or up, down, up, down. Both are legal, but the second one is better (in fact optimal) because it only requires a building of height 22, whereas the first one requires a building of height 42. If the distances are 3 2 5 3 1 2, an optimal legal solution is to go up, up, down, up, down, down. Note that for some distance sequences there is no legal solution at all (e.g., for 3 4 2 1 6 4 5).

Input
The first line of the input contains an integer N giving the number of test scenarios. The following 2N lines specify the test scenarios, two lines per scenario: the first line gives a positive integer M ≤ 40 which is the number of distances, and the following line contains the M positive integer distances. For any scenario, the total distance climbed (the sum of the distances in that scenario) is at most 1000.

Output
For each input scenario a single line should be output. This line should either be the string "IMPOSSIBLE" if no legal solution exists, or it should be a string of length M containing only the characters "U" and "D", where the i:th character indicates if Spiderman should climb up or down at the i:th stage. If there are several different legal and optimal solutions, output one of them (it does not matter which one as long as it is optimal).

Sample Input

3
4
20 20 20 20
6
3 2 5 3 1 2
7
3 4 2 1 6 4 5

Sample Output

UDUD
UUDUDD
IMPOSSIBLE

Source
Svenskt M?sterskap i Programmering 2003

ghost_wei說十分鐘就能打完, 汗, 牛人。。

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

const ? int ?MAXN? = ? 2001 ;
const ? int ?INF? = ? 2000000000 ;
int ?dp[ 41 ][MAXN];
int ?s[ 41 ][MAXN];
int ?a[ 41 ];

void ?print( int ?n,? int ?m)
{
????
if ?(n? == ? 0 )?
????????
return ?;

????
if ?(s[n][m]? == ? 0 )
????
{
????????print(n
- 1 ,?m - a[n]);
????????printf(
" U " );
????}

????
else
????
{
????????print(n
- 1 ,?m + a[n]);
????????printf(
" D " );
????}

}


void ?solve()
{
????
int ?n;
????
int ?i,?j;
????
int ?t1,?t2;
????
int ?maxn? = ? 0 ;

????scanf(
" %d " ,? & n);
????
for ?(i = 1 ;?i <= n;?i ++ )
????
{
????????scanf(
" %d " ,? & a[i]);
????????maxn?
+= ?a[i];
????}


????memset(dp,?
- 1 ,? sizeof (dp));
????memset(s,?
- 1 ,? sizeof (s));

????dp[
1 ][a[ 1 ]]? = ?a[ 1 ];
????s[
1 ][a[ 1 ]]? = ? 0 ;

????
for ?(i = 2 ;?i <= n;?i ++ )
????
{
????????
for ?(j = 0 ;?j < maxn;?j ++ )
????????
{
????????????t1?
= ?INF;
????????????t2?
= ?INF;
????????????
if ?(j - a[i]? >= ? 0 ? && ?dp[i - 1 ][j - a[i]]? != ? - 1 )
????????????????t1?
= ?max(j,?dp[i - 1 ][j - a[i]]);
????????????
if ?(j + a[i]? < ?maxn? && ?dp[i - 1 ][j + a[i]]? != ? - 1 )
????????????????t2?
= ?max(j,?dp[i - 1 ][j + a[i]]);
????????????
if ?(t1? < ?t2)
????????????
{
????????????????dp[i][j]?
= ?t1;
????????????????s[i][j]?
= ? 0 ;
????????????}

????????????
else
????????????
{
????????????????
if ?(t2? != ?INF)
????????????????
{
????????????????????dp[i][j]?
= ?t2;
????????????????????s[i][j]?
= ? 1 ;
????????????????}

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

????????}

????}

????
if ?(dp[n][ 0 ]? == ? - 1 )
????????printf(
" IMPOSSIBLE\n " );
????
else
????
{
????????print(n,?
0 );
????????printf(
" \n " );
????}

}


int ?main()
{
????
int ?caseTime;

????scanf(
" %d " ,? & caseTime);
????
while ?(caseTime -- ? != ? 0 )
????
{
????????solve();
????}

????
return ? 0 ;
}
posted on 2006-09-09 20:06 閱讀(473) 評論(1)  編輯 收藏 引用 所屬分類: ACM題目

FeedBack:
# re: pku(3003, 枚舉高度的dp)  2006-11-06 21:41 bmexue
竟然找到了,這道題我就是不會。
好好看看樓主的代碼  回復  更多評論
  
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
              亚洲国产精品成人久久综合一区| 亚洲成人在线视频播放| 亚洲一区免费网站| 99热免费精品| 亚洲在线观看视频网站| 亚洲欧美韩国| 久久精品国产2020观看福利| 久久精品99国产精品日本| 久久精品亚洲国产奇米99| 久久国产精品一区二区三区四区| 欧美在线一二三四区| 美女91精品| 欧美性猛交xxxx免费看久久久| 亚洲欧美精品| 国产日韩精品一区观看| 激情一区二区三区| 亚洲美女视频在线免费观看| 亚洲日本aⅴ片在线观看香蕉| 亚洲视频1区2区| 久久综合给合| 亚洲另类自拍| 久久精品日韩欧美| 欧美日韩伦理在线免费| 韩国精品一区二区三区| 日韩视频永久免费| 久久精品国产一区二区三区| 欧美丰满高潮xxxx喷水动漫| 一本色道久久综合一区| 久久久久在线| 国产乱码精品一区二区三区av| 亚洲精品午夜精品| 久久精品系列| 一区二区三区.www| 欧美a级片网| 极品日韩av| 欧美亚洲一级片| 日韩视频在线一区二区| 久久久国产精品亚洲一区 | 亚洲第一精品电影| 亚洲一区二区精品视频| 久久综合电影| 国产综合香蕉五月婷在线| 亚洲一区二区高清视频| 亚洲国产一区二区三区在线播 | 午夜伦欧美伦电影理论片| 欧美激情一区二区三区在线视频观看| 国产女同一区二区| 亚洲一区二区少妇| 亚洲免费av片| 欧美日韩国产成人高清视频| 亚洲国产一区二区a毛片| 久久裸体视频| 欧美在线观看天堂一区二区三区| 国产精品第2页| 中文精品99久久国产香蕉| 欧美激情小视频| 免费成人在线视频网站| 一区在线免费| 牛牛影视久久网| 久久米奇亚洲| 亚洲高清不卡av| 欧美成人免费va影院高清| 久久久久久久久久久久久女国产乱 | 久久综合色综合88| 亚洲欧美另类久久久精品2019| 欧美日韩中文在线观看| av成人手机在线| 亚洲欧洲精品一区二区| 欧美丰满高潮xxxx喷水动漫| 亚洲狼人综合| 一级日韩一区在线观看| 欧美午夜三级| 午夜视频一区二区| 午夜在线a亚洲v天堂网2018| 国产日韩在线看片| 美女诱惑一区| 欧美黄免费看| 午夜精品区一区二区三| 欧美在线观看日本一区| 亚洲人午夜精品免费| 一区二区三区精品国产| 国产视频久久久久久久| 欧美96在线丨欧| 欧美精品一区二区三区高清aⅴ| 亚洲一区999| 欧美影院成人| 亚洲美女在线一区| 亚洲欧美bt| 亚洲国产裸拍裸体视频在线观看乱了中文 | 亚洲大片精品永久免费| 欧美精品在线一区| 午夜国产精品视频| 久久夜色撩人精品| 一本色道久久综合精品竹菊| 亚洲免费影视第一页| 亚洲电影在线| 亚洲一区二区三区精品视频| 在线免费观看视频一区| 亚洲美女性视频| 国产一区二区0| 亚洲精品视频免费在线观看| 欧美三日本三级少妇三99| 久久精品在线| 欧美视频在线免费| 久久久久亚洲综合| 欧美日韩国产色综合一二三四 | 国产精品乱子乱xxxx| 久久日韩粉嫩一区二区三区| 牛牛精品成人免费视频| 亚洲欧美在线x视频| 久久精品中文字幕一区| 亚洲视频在线免费观看| 久久国内精品自在自线400部| 免费观看成人www动漫视频| 欧美日韩第一区日日骚| 久久久久9999亚洲精品| 欧美国产日本高清在线| 久久av最新网址| 欧美成人免费小视频| 欧美一区二区三区免费视| 老鸭窝毛片一区二区三区| 久久久www免费人成黑人精品| 欧美日韩在线播放一区| 最新高清无码专区| 亚洲国产日韩欧美| 久久永久免费| 久热re这里精品视频在线6| 国产女人精品视频| 亚洲欧美国产制服动漫| 亚洲欧洲av一区二区三区久久| 欧美日韩在线播放| av不卡在线观看| 亚洲先锋成人| 欧美日韩亚洲激情| 日韩小视频在线观看| 亚洲免费高清| 欧美日韩精品一区二区在线播放| 亚洲福利久久| 日韩视频不卡| 欧美色图首页| 亚洲一区二区三区在线播放| 亚洲综合首页| 国产精品丝袜xxxxxxx| 亚洲一区二区在线免费观看| 亚洲欧美日韩专区| 国产精品自在线| 久久国产高清| 欧美激情亚洲一区| 一区二区三区精品视频| 欧美日韩在线播放一区| 亚洲综合三区| 久久综合伊人77777| 亚洲人体影院| 欧美视频免费在线| 午夜精品电影| 欧美大片免费观看| 一本色道久久综合狠狠躁的推荐| 欧美午夜免费影院| 久久精品免费看| 最近看过的日韩成人| 亚洲一区二区视频| 狠狠色丁香久久综合频道| 老鸭窝亚洲一区二区三区| 亚洲精选一区| 久久久久久精| 一区二区三区av| 国产一区二三区| 欧美美女视频| 久久精品国产99| 最新中文字幕亚洲| 久久高清国产| 夜夜嗨网站十八久久| 国产午夜精品理论片a级大结局| 久久亚洲春色中文字幕久久久| 91久久国产综合久久91精品网站| 香蕉久久一区二区不卡无毒影院| 1024精品一区二区三区| 国产精品ⅴa在线观看h| 久久综合综合久久综合| 亚洲午夜视频| 亚洲国产欧美日韩精品| 欧美一区二区免费| 日韩午夜精品视频| 黄色资源网久久资源365| 国产精品一区二区三区四区| 精品91免费| 欧美成人中文| 亚洲欧美日韩区 | 一区二区国产精品| 久久综合九色综合久99| 99精品久久久| 韩曰欧美视频免费观看| 欧美日韩小视频| 久久久青草婷婷精品综合日韩| 久久在线播放| 欧美一级黄色录像| 亚洲精品中文字幕有码专区| 国产亚洲va综合人人澡精品| 欧美少妇一区二区| 欧美精品久久久久久久免费观看 |