• <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>
            心如止水
            Je n'ai pas le temps
            posts - 400,comments - 130,trackbacks - 0
            多重背包問題。將ni拆分成1,2,4,...,2^(k-1),ni-2^k+1,易證這種拆分可以組合出1..ni之間的所有數字。于是轉化成01背包求解。
            以下是我的代碼:
            /*
             * Author:  lee1r
             * Created Time:  2011/8/9 10:20:19
             * File Name: poj1276.cpp
             
            */
            #include
            <iostream>
            #include
            <sstream>
            #include
            <fstream>
            #include
            <vector>
            #include
            <list>
            #include
            <deque>
            #include
            <queue>
            #include
            <stack>
            #include
            <map>
            #include
            <set>
            #include
            <bitset>
            #include
            <algorithm>
            #include
            <cstdio>
            #include
            <cstdlib>
            #include
            <cstring>
            #include
            <cctype>
            #include
            <cmath>
            #include
            <ctime>
            #define L(x) ((x)<<1)
            #define R(x) (((x)<<1)+1)
            #define Half(x) ((x)>>1)
            #define lowbit(x) ((x)&(-(x)))
            using namespace std;
            const int kInf(0x7f7f7f7f);
            const double kEps(1e-8);
            typedef 
            long long int64;
            typedef unsigned 
            long long uint64;

            const int kMaxn(10007);
            const int kMaxm(100007);

            int n,m,cnt,w[kMaxn],c[kMaxn],d[kMaxm];

            int main()
            {
                
            //freopen("data.in","r",stdin);
                
                
            while(scanf("%d",&m)==1)
                {
                    cnt
            =0;
                    scanf(
            "%d",&n);
                    
            for(int i=1;i<=n;i++)
                    {
                        
            int ni,wi;
                        scanf(
            "%d%d",&ni,&wi);
                        
            for(int i=1;i<=ni;ni-=i,i<<=1)
                        {
                            cnt
            ++;
                            w[cnt]
            =wi*i;
                            c[cnt]
            =wi*i;
                        }
                        
            if(ni>0)
                        {
                            cnt
            ++;
                            w[cnt]
            =wi*ni;
                            c[cnt]
            =wi*ni;
                        }
                    }
                    
                    
            int ans(0);
                    memset(d,
            0,sizeof(d));
                    
            for(int i=1;i<=cnt;i++)
                        
            for(int j=m;j>=c[i];j--)
                            d[j]
            =max(d[j],d[j-c[i]]+w[i]);
                    
            for(int i=0;i<=m;i++)
                        ans
            =max(ans,d[i]);
                    
                    printf(
            "%d\n",ans);
                }
                
                
            return 0;
            }
            posted on 2011-08-09 10:38 lee1r 閱讀(380) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:動態規劃
            久久av免费天堂小草播放| 亚洲欧洲久久av| 99热都是精品久久久久久| 久久国产香蕉视频| 亚洲乱码精品久久久久..| 久久综合给合久久狠狠狠97色| 97久久久久人妻精品专区| 久久国产精品久久精品国产| 午夜精品久久久久久久无码| 69国产成人综合久久精品| 国产一区二区三区久久精品| 狠狠精品久久久无码中文字幕 | 久久精品无码午夜福利理论片 | 精品综合久久久久久88小说| 亚洲午夜无码久久久久| 一本久久a久久精品综合香蕉 | 亚洲精品美女久久777777| 久久人人超碰精品CAOPOREN| 五月丁香综合激情六月久久| 婷婷久久香蕉五月综合加勒比| 亚洲国产精品综合久久一线| 国产偷久久久精品专区| 亚洲色欲久久久综合网东京热| 97久久婷婷五月综合色d啪蜜芽| 品成人欧美大片久久国产欧美...| 久久91综合国产91久久精品| 色狠狠久久综合网| 国色天香久久久久久久小说| 99久久精品国产一区二区| 伊人久久久AV老熟妇色| 婷婷久久综合| 99久久国产综合精品五月天喷水 | 合区精品久久久中文字幕一区| 国产综合成人久久大片91| 久久久av波多野一区二区| 国产成人久久久精品二区三区| 99久久人人爽亚洲精品美女| 久久久精品国产Sm最大网站| 国产一区二区久久久| 久久精品国产99久久久香蕉| 久久久无码一区二区三区|