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

            newplan

            阿基米德在洗澡時發現浮力原理,高興得來不及穿上褲子,跑到街上大喊:Eureka(我找到了)。
            posts - 39, comments - 26, trackbacks - 0, articles - 4
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            greedy 部分背包問題

            Posted on 2008-05-13 17:17 山泉彎延 閱讀(428) 評論(0)  編輯 收藏 引用


            /*
             STL       map應用 
             
            * Greedy   部分背包問題 
             
            * newplan  開發時間:08.5.13  
            */
            /*--------INCLUDES----------*/ 
            #include 
            <cstdlib>
            #include 
            <iostream>
            #include 
            <map>
            #include 
            <fstream> 
            #include 
            <iomanip>
            /*--------INCLUDES----------*/ 

            /*---------MACROS-----------*/
            #define INPUTFILE  
            "bag.txt"
            /*---------MACROS-----------*/

            /*----------STD-------------*/
            using std::ifstream;
            using std::cout;
            using std::endl;
            using std::map;
            using std::greater;
            using std::ios;
            using std::setw;
            /*----------STD-------------*/

            /*-------GLOBAL VAL---------*/
            ifstream  Fin;
            int n;
            int W;
            int totalValue;
            /*-------GLOBAL VAL---------*/

            /*---------MAIN-------------*/
            int main(int argc, char *argv[])
            {  
             
                map
            <int,int,greater<int> > goods;
                
                Fin.open(INPUTFILE);
             
                
            int value;
                
                
            int weight;
                
                Fin
            >>W;
                
                Fin
            >>n;
                
                
            int i;
                
            for(i=0;i<n;i++)
                {
                   Fin
            >>value;
                   Fin
            >>weight;
                   goods[value]
            =weight;
                }

                
            for(map<int,int>::iterator it = goods.begin();it!=goods.end();it++)
                {
                 cout
            <<setiosflags(ios::left)<<"value:"<<setw(4)<<it->first
                 
            <<" weight:"<<setw(4)<<it->second<<endl;
                }
                
                
            for(map<int,int>::iterator it = goods.begin();it!=goods.end();it++)
                {
                  
            if(W-it->second>=0)
                  {
                     W
            -=it->second;
                     totalValue
            +=it->first*it->second;
                     cout
            <<"w="<<W<<" ";
                  }
                  
            else 
                  {
                     totalValue
            +=W*it->first;
                     cout
            <<"totalValue:"<<totalValue<<endl;
                     break;  
                  }
                  
                }
                
                system(
            "PAUSE");
                return EXIT_SUCCESS;
            }
            /*---------MAIN-------------*/
            BAG.TXT
            100   10
            3   43
            5   22
            6    4
            4   67
            2    3
            45  2
            4   2
            42  24
            41  4
            34  55

            久久精品免费观看| 久久国产精品成人影院| 久久精品日日躁夜夜躁欧美 | 欧美久久一区二区三区| 久久精品青青草原伊人| 四虎国产精品免费久久| 国产一级做a爰片久久毛片| 久久亚洲中文字幕精品一区| 久久久中文字幕| 国产亚洲精久久久久久无码| 久久成人国产精品免费软件| 久久久久这里只有精品 | 深夜久久AAAAA级毛片免费看 | 久久国产成人精品国产成人亚洲| 色婷婷久久综合中文久久蜜桃av| 久久影视综合亚洲| 婷婷久久综合九色综合九七| 国内精品久久久久久麻豆| 国内精品久久久久影院网站 | 国产∨亚洲V天堂无码久久久| 亚洲国产精品无码久久久蜜芽 | 久久精品国产福利国产秒| 久久香蕉超碰97国产精品| 久久精品国产精品青草app| 国内精品免费久久影院| 伊人久久五月天| 成人久久精品一区二区三区| 国产精品九九久久免费视频 | 亚洲伊人久久综合中文成人网 | 蜜桃麻豆WWW久久囤产精品| 婷婷久久香蕉五月综合加勒比| 久久国产精品-久久精品| 久久综合色之久久综合| 97精品国产91久久久久久| 久久久久国产成人精品亚洲午夜| 久久99热这里只频精品6| 狠狠久久亚洲欧美专区| 久久久久亚洲AV无码麻豆| 无码国内精品久久综合88| 伊人久久综合热线大杳蕉下载| 国内精品伊人久久久影院|