• <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久久精品国产一区二区| 久久九九有精品国产23百花影院| 亚洲欧美成人久久综合中文网| 国产毛片欧美毛片久久久| 久久青草国产精品一区| 久久精品国产99国产精品亚洲| 91久久精品国产成人久久| 午夜精品久久久久久久| 久久强奷乱码老熟女网站| 国产情侣久久久久aⅴ免费| 久久亚洲2019中文字幕| 中文字幕成人精品久久不卡 | 久久九九青青国产精品| 2021国内久久精品| 国产精品内射久久久久欢欢| 久久一日本道色综合久久| 精品国产日韩久久亚洲| 久久国产视频99电影| 伊人热人久久中文字幕| 久久精品一区二区国产| 久久久久亚洲AV无码网站| 久久久久久免费视频| 国产—久久香蕉国产线看观看| 久久成人影院精品777| 久久精品国产99久久久| 婷婷久久香蕉五月综合加勒比| 国产精品中文久久久久久久| 免费一级欧美大片久久网| 精品久久久久久无码人妻蜜桃| 久久97久久97精品免视看| 久久免费香蕉视频| 久久婷婷午色综合夜啪| 国产精品成人久久久|