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

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

            POJ 1947 Rebuilding Roads 第一個樹形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代表當前訪問結點
            {
                
            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 閱讀(1246) 評論(0)  編輯 收藏 引用

            国产成年无码久久久久毛片| 色妞色综合久久夜夜| 91精品国产91久久综合| 久久最新精品国产| 大蕉久久伊人中文字幕| 亚洲精品97久久中文字幕无码| 97精品伊人久久大香线蕉| 欧美精品乱码99久久蜜桃| 久久综合久久自在自线精品自| 亚洲国产成人久久综合一 | 欧美噜噜久久久XXX| 久久亚洲国产精品一区二区| 欧美久久一级内射wwwwww.| 久久久久久久综合狠狠综合| 国产精品毛片久久久久久久 | 久久成人小视频| 精品久久久无码人妻中文字幕豆芽| 国产精品99久久久久久www| 久久综合久久综合亚洲| 国产美女久久精品香蕉69| 伊人久久大香线蕉综合5g| 久久AV高清无码| 久久精品无码一区二区三区日韩| 久久久久亚洲爆乳少妇无| 国产午夜电影久久| 国产激情久久久久影院老熟女| 久久综合亚洲色HEZYO社区| 欧美亚洲另类久久综合| 中文字幕乱码人妻无码久久| 久久久久一本毛久久久| 久久99国产亚洲高清观看首页 | 国内精品久久久久久麻豆| 久久综合88熟人妻| 一本色道久久99一综合| 亚洲欧美成人久久综合中文网| 88久久精品无码一区二区毛片| 久久国产欧美日韩精品| 久久综合给合久久狠狠狠97色69| 久久午夜无码鲁丝片秋霞| 久久久久久久久66精品片| 18禁黄久久久AAA片|