• <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之間的所有數(shù)字。于是轉(zhuǎn)化成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 閱讀(373) 評論(0)  編輯 收藏 引用 所屬分類: 題目分類:動態(tài)規(guī)劃
            久久九九免费高清视频| 久久青青草视频| 91精品国产综合久久精品| 久久精品国产99国产精偷| 国产成人久久精品激情| 欧美日韩中文字幕久久伊人| 99久久国产综合精品网成人影院| 久久99精品久久久久久水蜜桃 | 国产99精品久久| 夜夜亚洲天天久久| 亚洲天堂久久久| 国产精品99久久精品| 日批日出水久久亚洲精品tv| 青青草原综合久久大伊人| 69久久精品无码一区二区| 久久久久久久综合综合狠狠| 无码人妻精品一区二区三区久久 | 久久天天躁狠狠躁夜夜96流白浆 | 久久精品人人做人人爽电影| 久久亚洲欧洲国产综合| 狠狠色丁香久久婷婷综合五月| 久久免费精品一区二区| 久久精品国产清自在天天线| 爱做久久久久久| 99久久超碰中文字幕伊人| 伊人久久一区二区三区无码| 日本精品久久久久中文字幕8| 伊人久久大香线蕉综合5g| 亚洲一本综合久久| 久久精品国产亚洲AV麻豆网站| 欧美午夜A∨大片久久| 99久久综合狠狠综合久久| 久久久久久久久久久久中文字幕| 欧美性猛交xxxx免费看久久久| 色噜噜狠狠先锋影音久久| 国产V综合V亚洲欧美久久| 国产69精品久久久久9999APGF | 久久99国产乱子伦精品免费| 久久久黄色大片| 午夜视频久久久久一区| 久久综合五月丁香久久激情|