• <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 山泉彎延 閱讀(434) 評論(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

            99久久精品国产高清一区二区| 日日噜噜夜夜狠狠久久丁香五月| 国产香蕉97碰碰久久人人| 久久综合精品国产一区二区三区| 久久久这里只有精品加勒比| 国产高潮国产高潮久久久| 午夜精品久久久久9999高清| 嫩草伊人久久精品少妇AV| 久久久免费观成人影院| 国产精品久久免费| 久久精品无码一区二区WWW| 国产香蕉97碰碰久久人人| 久久久久99精品成人片欧美| 久久久久久午夜精品| 久久国产精品免费| 久久国产高清字幕中文| 久久久久99精品成人片欧美| 久久人人爽人人爽人人片AV高清| 久久国产成人午夜aⅴ影院| 狠狠色丁香婷婷久久综合不卡| 久久综合亚洲色HEZYO社区| 久久强奷乱码老熟女网站| 久久综合狠狠综合久久激情 | 成人精品一区二区久久| 久久精品午夜一区二区福利| 久久精品国产亚洲AV久| 18禁黄久久久AAA片| 一本久久a久久精品综合香蕉| 久久男人AV资源网站| 免费一级欧美大片久久网| 久久久久人妻一区精品| 青青热久久国产久精品| 久久乐国产精品亚洲综合| 蜜臀久久99精品久久久久久| 亚洲欧美国产精品专区久久| 久久天天躁狠狠躁夜夜不卡| 久久精品免费全国观看国产| 无码AV中文字幕久久专区| 国产国产成人精品久久| 久久综合久久综合久久综合| 国产日韩欧美久久|