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

            The Fourth Dimension Space

            枯葉北風(fēng)寒,忽然年以殘,念往昔,語(yǔ)默心酸。二十光陰無(wú)一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢(mèng)令

            POJ 1947 Rebuilding Roads 第一個(gè)樹(shù)形DP

            After solving this problem,I can't help admitting that DP is a world which fully fill with amazement,from the simple one dimension DP,to two dimension DP even to staue DP,tree DP,DP problem is just like a kaleidoscope. But the further reflection reveal that it is always the same because of the similar essence.in my eyes,every DP problem has a (mostly two dimension)table and a equation bewteen two states.If we can controll the table and the relationship between every states,we can conque the problem completely.
            The following is my code ,according to the big fish foreverlin.
             
            #include<iostream>
            #include
            <cmath>
            #include
            <algorithm>
            #include
            <vector>
            using namespace std;
            #define INF 999999999
            #define MAX 151
            vector
            <int> hash[MAX];
            int dp[MAX][MAX];
            int n,p;

            void dfs(int x)//x代表當(dāng)前訪問(wèn)結(jié)點(diǎn)
            {
                
            int i,j,k;
                
            int len=hash[x].size();
                
            for(i=0;i<len;i++)
                    dfs(hash[x][i]);
                
            //////////////////////////////////////////////////////////////////////////
                //后序遍歷,從葉子往上逐層遞推
                if(x==1)    dp[x][1]=hash[x].size();
                
            else dp[x][1]=hash[x].size()+1;
                
            for(k=0;k<len;k++)
                
            {
                    
            for(i=p-1;i>=1;i--)
                    
            {
                        
            if(dp[x][i]!=INF)
                        
            {
                            
            for(j=1;i+j<=p;j++)
                            
            {
                                
            if(dp[hash[x][k]][j]!=INF)
                                    dp[x][i
            +j]=min(dp[x][i+j],dp[x][i]+dp[hash[x][k]][j]-2);
                            }

                        }

                    }

                }

            }




            int main()
            {
                scanf(
            "%d%d",&n,&p);
                
            int i,j;
                
            int t1,t2;
                
            for(i=1;i<=n-1;i++)
                
            {
                    scanf(
            "%d%d",&t1,&t2);
                    hash[t1].push_back(t2);
                }

                
            for(i=1;i<=n;i++)
                    
            for(j=1;j<=p;j++)
                        dp[i][j]
            =INF;
                dfs(
            1);
                
            int ans=INF;
                
            for(i=1;i<=n;i++)
                
            {
                    
            if(dp[i][p]<ans)
                        ans
            =dp[i][p];
                }

                printf(
            "%d\n",ans);
                
            return 0;
                
                


            }

            posted on 2010-03-07 23:36 abilitytao 閱讀(1245) 評(píng)論(0)  編輯 收藏 引用


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


            久久亚洲精品国产亚洲老地址| 久久精品国产亚洲AV蜜臀色欲| 91性高湖久久久久| 精品国产热久久久福利| 日韩影院久久| 99久久99这里只有免费费精品| 青青青伊人色综合久久| 久久久噜噜噜久久中文字幕色伊伊| 久久精品免费全国观看国产| 狠狠色婷婷久久一区二区三区| 99久久精品国产麻豆| 99国产欧美久久久精品蜜芽| 精品多毛少妇人妻AV免费久久| 久久精品免费全国观看国产| 亚洲日韩中文无码久久| 久久综合久久综合久久| 久久精品国产亚洲一区二区三区| 婷婷久久综合九色综合绿巨人| 国产亚洲欧美精品久久久| 久久久无码精品亚洲日韩软件| 久久A级毛片免费观看| 亚洲美日韩Av中文字幕无码久久久妻妇| 嫩草伊人久久精品少妇AV| 久久久久成人精品无码 | 久久久久久久久波多野高潮| 99久久免费国产精品| 国产99精品久久| 国产激情久久久久久熟女老人 | 亚洲国产精品久久久天堂| 狠狠综合久久综合88亚洲 | 久久久中文字幕日本| 一级a性色生活片久久无| 国产三级精品久久| 99久久成人国产精品免费| 无码国内精品久久人妻| 2020久久精品亚洲热综合一本 | 亚洲日本久久久午夜精品| 午夜视频久久久久一区| 99久久无码一区人妻| 91精品国产综合久久婷婷| 一本一本久久aa综合精品|