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


            久久99国产精品久久| 日本精品久久久久久久久免费| 伊色综合久久之综合久久| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久人人爽人人爽人人片AV不| 亚洲va国产va天堂va久久| 久久久久免费精品国产| 亚洲国产成人久久综合野外| 久久久高清免费视频| 国产精品9999久久久久| 久久久久国产精品三级网| 久久久噜噜噜久久熟女AA片| 久久精品亚洲欧美日韩久久| 欧美噜噜久久久XXX| 亚洲а∨天堂久久精品| 夜夜亚洲天天久久| 久久精品国产亚洲AV无码麻豆| 久久天天躁狠狠躁夜夜2020老熟妇 | 狠狠色丁香婷婷久久综合| 久久精品九九亚洲精品天堂| 久久久久久久久波多野高潮| 久久影视综合亚洲| 国内精品久久久久久久影视麻豆| 国产精品禁18久久久夂久| 久久精品国产欧美日韩99热| 国内精品久久久久影院网站| 久久久中文字幕| 好久久免费视频高清| 久久精品国产亚洲AV嫖农村妇女| 久久国产视屏| 久久精品一区二区影院| 亚洲国产成人久久综合一| 女人香蕉久久**毛片精品| 国产精品99久久99久久久| 99久久精品午夜一区二区 | 中文国产成人精品久久亚洲精品AⅤ无码精品 | 日韩欧美亚洲综合久久影院d3| 97久久久久人妻精品专区 | 久久精品国产免费观看三人同眠| 亚洲?V乱码久久精品蜜桃 | 亚洲国产二区三区久久|