• <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>

            USACO 3.4 Raucous Rockers


            一開始把題意理解錯了,以為刻在同一張光盤上的歌曲的時間順序不變就可以了。
            事實上不僅同光盤上的歌曲寫入時間要按順序,前一張光盤上的歌曲不能比后一張歌曲寫入時間要晚。

            數據量比較少,用回溯法,dp也行。

            #include?<iostream>
            #include?
            <fstream>

            using?namespace?std;

            ifstream?fin(
            "rockers.in");
            ofstream?fout(
            "rockers.out");

            #ifdef?_DEBUG
            #define?out?cout
            #define?in?cin
            #else
            #define?out?fout
            #define?in?fin
            #endif

            int?capacity[20];;
            int?songs[20];
            int?song_num,disk_num;

            int?res?=?0;
            int?cur;

            void?backtracing(int?depth,int?last)
            {
            ????
            if(depth==song_num){
            ????????
            if(cur>res){
            ????????????res?
            =?cur;
            ????????}
            ????????
            return;
            ????}
            ???
            ??? //如果后面所有的歌曲都加上還比最優值小,剪枝
            ????
            if(cur+song_num-depth<=res)
            ???????
            return;?

            ????
            for(int?i=last;i<disk_num;++i){
            ???????? //如果當前歌曲需要刻錄,那只需刻在第一張能裝得下的光盤上。
            ????????
            if(?capacity[i]>=songs[depth]){
            ????????????cur
            ++;
            ????????????capacity[i]
            -=songs[depth];
            ????????????backtracing(depth
            +1,i);
            ????????????capacity[i]
            +=songs[depth];
            ????????????cur
            --;
            ????????????
            break;
            ????????}
            ????}

            ??? // 不刻當前歌曲
            ????backtracing(depth
            +1,last);

            }

            void?solve()
            {
            ????
            int?c;
            ????
            in>>song_num>>c>>disk_num;

            ????
            for(int?i=0;i<song_num;++i)
            ????????
            in>>songs[i];

            ????
            for(int?i=0;i<disk_num;++i)
            ????????capacity[i]?
            =?c;

            ????backtracing(
            0,0);

            ????
            out<<res<<endl;
            }

            int?main(int?argc,char?*argv[])
            {
            ????solve();?
            ????
            return?0;
            }


            posted on 2009-07-11 11:48 YZY 閱讀(1437) 評論(0)  編輯 收藏 引用 所屬分類: AlgorithmUSACO回溯法搜索

            導航

            <2011年1月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            統計

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            亚洲av伊人久久综合密臀性色| 欧美日韩精品久久免费| 久久99中文字幕久久| 久久电影网一区| 综合久久给合久久狠狠狠97色| 色狠狠久久AV五月综合| 国产成人精品久久亚洲高清不卡 | 欧美午夜A∨大片久久 | 久久精品中文字幕一区| 久久丫忘忧草产品| 国产精品欧美亚洲韩国日本久久| 亚洲国产一成久久精品国产成人综合| 久久综合88熟人妻| 亚洲人成网站999久久久综合 | 国产91久久综合| 久久久婷婷五月亚洲97号色| 久久久久亚洲AV无码去区首| 成人国内精品久久久久影院| 欧美久久天天综合香蕉伊| 99久久99这里只有免费的精品| 久久精品国产久精国产果冻传媒 | 人人狠狠综合久久亚洲婷婷| 久久精品国产2020| 久久天天躁狠狠躁夜夜2020老熟妇| 国产高潮国产高潮久久久| 午夜精品久久久久久久久| 亚洲人成无码久久电影网站| 狠狠色伊人久久精品综合网| 热久久这里只有精品| 久久九九亚洲精品| 国产精品岛国久久久久| av无码久久久久不卡免费网站| 久久久久99精品成人片试看| 久久九九精品99国产精品| 午夜天堂精品久久久久| 亚洲精品乱码久久久久久自慰| 亚洲精品无码久久久久| 午夜欧美精品久久久久久久| 国产美女久久久| 国产成人精品久久一区二区三区av| 久久精品九九亚洲精品天堂|