• <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>
            隨筆 - 87  文章 - 279  trackbacks - 0
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            潛心看書研究!

            常用鏈接

            留言簿(19)

            隨筆分類(81)

            文章分類(89)

            相冊(cè)

            ACM OJ

            My friends

            搜索

            •  

            積分與排名

            • 積分 - 216643
            • 排名 - 117

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            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 閱讀(453) 評(píng)論(1)  編輯 收藏 引用 所屬分類: ACM題目

            FeedBack:
            # re: pku(3003, 枚舉高度的dp)  2006-11-06 21:41 bmexue
            竟然找到了,這道題我就是不會(huì)。
            好好看看樓主的代碼  回復(fù)  更多評(píng)論
              
            一级女性全黄久久生活片免费 | 久久这里有精品视频| 久久99精品久久久久久hb无码| 日韩美女18网站久久精品 | 久久午夜羞羞影院免费观看| 久久久久99精品成人片三人毛片| 日本精品久久久久中文字幕| 久久男人Av资源网站无码软件| 99久久国产综合精品女同图片| 久久久久九九精品影院| 久久夜色精品国产亚洲av| 久久精品成人| 无码人妻久久一区二区三区免费丨 | 麻豆精品久久久一区二区| 久久AV高清无码| 久久精品国产一区二区三区| 精品久久人人爽天天玩人人妻| 老司机午夜网站国内精品久久久久久久久 | 国产精品久久久久久久久久影院| 污污内射久久一区二区欧美日韩| 亚洲精品WWW久久久久久 | 国产精品gz久久久| 久久亚洲精品成人无码网站| 国产精品岛国久久久久| 久久99精品九九九久久婷婷| 久久亚洲AV成人无码软件| 国产精品福利一区二区久久| 亚洲婷婷国产精品电影人久久| 久久亚洲美女精品国产精品| 久久国产精品免费一区| 国内精品久久久久影院优| 久久国产亚洲精品| 2020最新久久久视精品爱 | 国产亚洲精久久久久久无码77777| 久久综合久久综合九色| 日本久久久久亚洲中字幕| 久久精品国产亚洲AV蜜臀色欲| 91精品婷婷国产综合久久| 国产成人无码久久久精品一| 久久精品国产亚洲av麻豆图片| 久久无码人妻精品一区二区三区|