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

            O(1) 的小樂

            Job Hunting

            公告

            記錄我的生活和工作。。。
            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            統(tǒng)計

            • 隨筆 - 182
            • 文章 - 1
            • 評論 - 41
            • 引用 - 0

            留言簿(10)

            隨筆分類(70)

            隨筆檔案(182)

            文章檔案(1)

            如影隨形

            搜索

            •  

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            USACO 2.3 Money Systems

            /*
            ID: lvxiaol3
            LANG: C++
            TASK: money
            */
            #include <iostream>
            #include <vector>
            #include <fstream>
            #include <algorithm>
            #include <string>
            #include <set>
            #include <cstdio>
            using namespace std;

             

            int main()
            {
                ifstream fin("money.in");
                ofstream fout("money.out");
                int V, N;
                fin>>V>>N;
                vector<int> Coin(V);
                for(int i=0; i<V; i++) fin>>Coin[i];
                sort(Coin.begin(),Coin.end());

                long long  dp[2][10005];
                for(int i=0;i<V; i++) dp[i%2][0]=1LL;
                int temp=Coin[0];
                while(temp<=N) {dp[0][temp]=1;temp+=Coin[0];}

                for(int i=1; i<V;i++)
                {
                    for(int j=1;j<=N;j++)
                    {
                        int m=j;
                        dp[i%2][j]=0;
                        while(m>=0)
                        {
                            dp[i%2][j]+=dp[(i-1)%2][m];
                            m-=Coin[i];
                        }
                    }
                }
                fout<<dp[(V-1)%2][N]<<endl;


                return 0;
            }
            /*
            3 10
            1 2 5

            1 1 1 1 1 1 1 1 1 1 1
            1 1 2 2 3 3 4 4 5 5 6
            1 1 2 2 3 4 5 6 7 8 10
            10

            Process returned 0 (0x0)   execution time : 0.027 s
            Press any key to continue.

            */
            // dp[k][n] the previous k kind of coins consist of n
            // dp[k][n]= /sum{dp[k-1][n-p*v[k]] } p>=0

             

            下面這一步的dp優(yōu)化贊!利用DP狀態(tài)改變的順序來優(yōu)化dp的復(fù)雜度
            /*
            for(i=0; i<v; i++) {
                    fscanf(fin, "%d", &c);

                    for(j=c; j<=n; j++)
                        nway[j] += nway[j-c];
                }
            */

            posted on 2011-10-19 22:14 Sosi 閱讀(125) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            統(tǒng)計系統(tǒng)
            午夜精品久久影院蜜桃| 精品免费久久久久久久| 久久久久一本毛久久久| 久久亚洲国产精品成人AV秋霞| 久久婷婷五月综合97色直播| 精品熟女少妇AV免费久久| 久久人人爽人人人人爽AV| 久久久久久午夜成人影院| 久久天天躁狠狠躁夜夜不卡| 91精品国产乱码久久久久久| 国产高潮久久免费观看| 久久精品中文字幕一区| 国产精品99久久不卡| 无码精品久久久天天影视| 久久国产免费| 69久久精品无码一区二区| 人人狠狠综合久久亚洲| 久久综合久久综合久久综合| 成人久久免费网站| 久久久精品国产亚洲成人满18免费网站| 久久久久久久精品妇女99| 久久久久女教师免费一区| 国产高潮国产高潮久久久| 午夜精品久久久久久久| 性高朝久久久久久久久久| 91久久精品国产91性色也| 精品乱码久久久久久久| 无码专区久久综合久中文字幕| 久久亚洲AV成人无码软件| 久久国语露脸国产精品电影| 亚洲中文字幕伊人久久无码| 久久人妻少妇嫩草AV蜜桃| 国产国产成人久久精品| 国产一区二区精品久久| 好属妞这里只有精品久久| 久久男人Av资源网站无码软件| 国产偷久久久精品专区| 日韩精品久久无码中文字幕| 色综合久久无码五十路人妻| 久久亚洲AV成人无码电影| 久久久精品人妻一区二区三区四 |