• <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代表當前訪問結(jié)點
            {
                
            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 閱讀(1252) 評論(0)  編輯 收藏 引用

            一本色道久久88综合日韩精品| 超级97碰碰碰碰久久久久最新| 久久精品天天中文字幕人妻| 久久久久AV综合网成人| 久久本道伊人久久| 亚洲国产视频久久| 国产精品国色综合久久| 久久精品国产黑森林| 亚洲午夜久久久影院| 国产成人精品久久一区二区三区av| 欧美国产精品久久高清| 色8久久人人97超碰香蕉987| 久久国产香蕉一区精品| 国产Av激情久久无码天堂| 亚洲欧美国产日韩综合久久| 99精品久久久久久久婷婷| 亚洲午夜久久久久久久久久| 亚洲人成电影网站久久| 久久精品亚洲乱码伦伦中文| 久久99热只有频精品8| 久久精品国产亚洲AV影院| 狠狠人妻久久久久久综合| 国产精品久久毛片完整版| 精品久久久无码人妻中文字幕 | 亚洲综合久久综合激情久久| 久久天天躁夜夜躁狠狠| 狠狠色丁香婷婷综合久久来来去| 国产成年无码久久久久毛片| 亚洲va久久久噜噜噜久久男同| 热综合一本伊人久久精品| 亚洲国产精品婷婷久久| 青青国产成人久久91网| 国产精品久久久久久搜索| 久久夜色精品国产噜噜亚洲AV| 国内高清久久久久久| 区久久AAA片69亚洲| 中文字幕人妻色偷偷久久| 亚洲熟妇无码另类久久久| 亚洲AV无码久久精品蜜桃| 亚洲精品美女久久777777| 国产91色综合久久免费|