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

            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代表當(dāng)前訪問結(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 閱讀(1241) 評論(0)  編輯 收藏 引用

            久久这里只有精品首页| 久久久久久亚洲AV无码专区| 噜噜噜色噜噜噜久久| 国产精品久久波多野结衣| 久久精品这里只有精99品| 国产精品久久自在自线观看| 久久人人爽人人爽人人片AV高清| 亚洲AV无码久久精品成人| 91精品国产91久久久久久青草| 亚洲欧美成人久久综合中文网 | 久久99精品久久久久久水蜜桃 | 色欲久久久天天天综合网精品| 久久亚洲中文字幕精品一区| 成人亚洲欧美久久久久 | 久久99国产精品尤物| 欧美喷潮久久久XXXXx| 丰满少妇高潮惨叫久久久| 久久夜色精品国产网站| 久久精品人成免费| 国产精品视频久久| segui久久国产精品| 久久免费国产精品一区二区| 欧美一区二区精品久久| 亚洲国产成人久久精品动漫| 91精品观看91久久久久久| 久久国产精品波多野结衣AV| 亚洲精品成人久久久| 狠狠综合久久AV一区二区三区| 国内精品伊人久久久久av一坑| 久久不射电影网| 亚洲国产成人久久综合区| 午夜精品久久久久久中宇| 2020最新久久久视精品爱| 亚洲伊人久久综合影院| 久久精品无码午夜福利理论片| 99久久无色码中文字幕| 亚洲AⅤ优女AV综合久久久| 精品免费久久久久久久| 久久久久九国产精品| 国产精品久久久天天影视| 日日狠狠久久偷偷色综合免费|