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

            misschuer

            常用鏈接

            統計

            積分與排名

            百事通

            最新評論

            hdu 1074 Doing Homework

            #include <iostream>
            #define MAXM 1 << 16
            #include 
            <vector>
            #include 
            <cmath>
            #define MAXN 16
            #include 
            <string>
            using namespace std;

            typedef 
            struct {
                
                
            string obj;
                
            int deadline;
                
            int needday;
            }Point;
            //所需天數, 前一個狀態, 最少損失.
            typedef struct {
                
                
            int nedday;
                
            int fStatus;
                
            int lostScore;
            }Node;

            Point p[MAXN];

            Node dp[MAXM];
            bool vist[MAXM];
            int n;

            void print(int status) {

                vector
            <string> V;
                
            int pre = status;

                
            while(dp[status].fStatus != -1) {
                
                    
            int crr = dp[status].fStatus;
                    
            int s = crr ^ pre;

                    
            int cc = log(s + 0.00000001/ log(2.0);

                    V.push_back(p[ cc ].obj);
                    pre 
            = crr;
                    status 
            = pre;
                }

                
            for(int i = V.size() - 1; i >= 0-- i) {
                
                    cout 
            << V[ i ] << endl;
                }
            }

            void res() {
                
                memset(vist, 
            falsesizeof(vist));
                dp[ 
            0 ].nedday = 0;
                dp[ 
            0 ].fStatus = -1;
                dp[ 
            0 ].lostScore = 0;
                
                
            int upper = (1 << n) - 1;
                
                
            for(int j = 0; j < upper; ++ j) {
                    
                    
            for(int i = 0; i < n; ++ i) {
                        
                        
            int crr = 1 << i;

                        
            if((crr & j) == 0) {

                            
            //作業i完成時的狀態
                            int curtmp = (crr | j);

                            
            //作業i完成時消耗的時間
                            dp[curtmp].nedday = dp[ j ].nedday + p[ i ].needday;
                            
                            
            //作業i完成時超期的時間
                            int reduce = dp[curtmp].nedday - p[ i ].deadline;
                            
                            
            //若不超期
                            if(reduce < 0) reduce = 0;

                            
            //累加前一個狀態的超期時間
                            reduce += dp[ j ].lostScore;

                            
                            
            if(vist[curtmp]) {
                                
                                
            //該狀態訪問過
                                if(reduce < dp[curtmp].lostScore) {
                                
                                    dp[curtmp].lostScore 
            = reduce;
                                    dp[curtmp].fStatus 
            = j;
                                }
                            }
                            
            else if(!vist[curtmp]) {
                                
                                
            //該狀態尚未訪問
                                    vist[curtmp] = true;
                                    dp[curtmp].lostScore 
            = reduce;
                                    dp[curtmp].fStatus 
            = j;
                            }
                        }
                    }
                }

                printf(
            "%d\n", dp[upper].lostScore);
                
                
            /*
                for(int i = 0; i <= upper; ++ i) {
                
                    cout << i << " " << dp[ i ].fStatus << " " << dp[ i ].lostScore << " " << dp[ i ].nedday << endl;
                }
                
            */

                print(upper);
            }

            int main() {
                
                
            int test;
                cin 
            >> test;
                
                
            while(test --) {
                    
                    cin 
            >> n;
                    
            for(int i = 0; i < n; ++ i) {
                        
                        cin 
            >> p[ i ].obj >> p[ i ].deadline >> p[ i ].needday;
                    }
                    
                    res();
                }
                
            return 0;

            posted on 2011-03-13 20:58 此最相思 閱讀(251) 評論(0)  編輯 收藏 引用

            .精品久久久麻豆国产精品| 国产成人99久久亚洲综合精品| 久久久国产99久久国产一| 亚洲中文字幕伊人久久无码 | 久久久久无码中| 波多野结衣久久一区二区| 国产精品久久久久jk制服| 久久一区二区三区免费| 精品久久一区二区| 久久婷婷五月综合色奶水99啪| 久久无码人妻一区二区三区午夜| 国产高清国内精品福利99久久| 一本久久知道综合久久| 久久久久亚洲AV成人网人人网站 | 精品久久久久久久久久中文字幕| 久久精品免费一区二区| 久久精品国产精品亜洲毛片| 久久综合综合久久综合| 蜜桃麻豆WWW久久囤产精品| 麻豆精品久久精品色综合| 久久国产亚洲精品无码| 免费无码国产欧美久久18| 免费一级欧美大片久久网| 97精品伊人久久久大香线蕉| 狠狠干狠狠久久| 精品999久久久久久中文字幕| 色妞色综合久久夜夜| 久久精品极品盛宴观看| 精品水蜜桃久久久久久久| 伊人色综合久久天天| 精品久久国产一区二区三区香蕉| 久久99精品国产99久久| 久久久国产精品福利免费| 精品久久久久久亚洲| 久久噜噜电影你懂的| 久久99国产亚洲高清观看首页| 久久精品国产精品青草| 久久综合狠狠综合久久激情 | 青青青国产成人久久111网站| 99久久人妻无码精品系列 | 日韩AV无码久久一区二区 |