• <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>
            隨筆-72  評論-126  文章-0  trackbacks-0
            http://acm.hdu.edu.cn/showproblem.php?pid=2196
            向下搜一遍,向上搜一遍
            http://acm.hdu.edu.cn/showproblem.php?pid=1561
            對每一個節點進行一次背包,好題啊,兩個DP樹形和背包結合的
            http://acm.hdu.edu.cn/showproblem.php?pid=1011
            這道是當年省賽的壓軸題,但是感覺和上一道差不多,一樣的難度,唯一不同的就是這個是無向圖(我由于思維慣性拿來當單向圖作,糾結了好久。。。)
            樹形+背包+臨街表

            下邊是從天涯空間里找出來的練習
            http://acm.pku.edu.cn/JudgeOnline/problem?id=3345
            http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3201
            http://acm.pku.edu.cn/JudgeOnline/problem?id=3107
            http://acm.pku.edu.cn/JudgeOnline/problem?id=1655
            http://acm.pku.edu.cn/JudgeOnline/problem?id=2378
            http://acm.pku.edu.cn/JudgeOnline/problem?id=3140
            http://acm.hdu.edu.cn/showproblem.php?pid=2242
            http://acm.timus.ru/problem.aspx?space=1&num=1018
            http://acm.pku.edu.cn/JudgeOnline/problem?id=1947
            http://acm.pku.edu.cn/JudgeOnline/problem?id=2057
            http://acm.pku.edu.cn/JudgeOnline/problem?id=2486
            http://acm.pku.edu.cn/JudgeOnline/problem?id=1848
            http://acm.pku.edu.cn/JudgeOnline/problem?id=2152



            http://acm.hdu.edu.cn/showproblem.php?pid=1520
            (第一個樹形DP,附代碼)
            最最簡單的樹形DP
            還學習了父子兄弟結構,爽

            #include "stdio.h"

            struct Tree{
                
            int father;
                
            int child;
                
            int brother;
                
            int TakeParty;
                
            int Not;
                
            int Max() {
                    
            return TakeParty > Not ? TakeParty : Not;
                }
                
            void init() {
                    father 
            = child = brother = Not = 0;
                }
            }tree[
            6001];

            void dfs(int idx ) {
                
            int child;
                child 
            = tree[idx].child;
                
            while(child) {
                    dfs(child);
                    tree[idx].TakeParty 
            += tree[child].Not;
                    tree[idx].Not 
            += tree[child].Max();
                    child 
            = tree[child].brother;
                }
            }

            int main() {
                
            int n,i,a,b;
                
            while(scanf("%d",&n) == 1) {
                    
            for(i =1 ; i <= n ; i ++) {
                        scanf(
            "%d",&tree[i].TakeParty);
                        tree[i].init();
                    }
                    
            while(scanf("%d%d",&a,&b),a+b) {
                        tree[a].father 
            = b;
                        tree[a].brother 
            = tree[b].child;
                        tree[b].child 
            = a;
                    }
                    
            for(i = 1 ; i <= n ; i ++) {
                        
            if(!tree[i].father) {
                            dfs(i);
                            printf(
            "%d\n",tree[i].Max());
                            
            break;
                        }
                    }
                }
                
            return 0;
            }

            posted on 2009-05-11 20:39 shǎ崽 閱讀(6168) 評論(4)  編輯 收藏 引用

            評論:
            # re: 樹形DP 2009-05-12 17:16 | zjfc3
            左兒子右兄弟法??不錯  回復  更多評論
              
            # re: 樹形DP 2010-08-08 11:36 | TT
            LZ有沒hdu 1561的代碼 學習下  回復  更多評論
              
            # re: 樹形DP 2013-04-07 21:29 | 隨心小亞
            @TT
            1561 的代碼我有,但是不知道如何判斷-1的情況:
            var
            n,m,i:longint;
            fa,w:array [1..200] of longint;
            f:array [0..200,0..200] of longint;
            procedure dfs(h,s:longint);
            var
            i,j:longint;
            begin
            if s<=0 then exit;
            for i:=1 to n do
            if fa[i]=h then begin
            for j:=0 to s-1{cost[child]} do f[i,j]:=f[h,j];
            dfs(i,s-1{cost[child]});
            for j:=1{cost[child]} to s do
            if f[h,j]<f[i,j-1]+w[i] then
            f[h,j]:=f[i,j-1]+w[i];
            end;
            end;
            begin
            repeat
            readln(n,m);
            if not ((n=0)and(m=0)) then begin
            for i:=1 to n do readln(fa[i],w[i]);
            dfs(0,m-0);
            writeln(f[0,m-0]);
            end;
            until (n=0)and(m=0);
            end.  回復  更多評論
              
            久久精品国产福利国产秒| 久久久亚洲精品蜜桃臀| 漂亮人妻被黑人久久精品| 国内精品久久久久久99蜜桃| 热99re久久国超精品首页| 精品国产婷婷久久久| 香蕉aa三级久久毛片| 9久久9久久精品| 欧美亚洲国产精品久久高清| 国产精品天天影视久久综合网| 精品久久久久国产免费| 伊人久久大香线蕉综合影院首页| 久久夜色tv网站| 无码AV波多野结衣久久| 久久强奷乱码老熟女网站| 久久国产精品无码HDAV| 日日狠狠久久偷偷色综合0| 99久久超碰中文字幕伊人| 亚洲一区精品伊人久久伊人 | 久久播电影网| 久久精品国产亚洲av影院| 中文成人久久久久影院免费观看| 秋霞久久国产精品电影院| 日本强好片久久久久久AAA | 久久久久中文字幕| 亚洲国产精品无码久久久不卡| 亚洲精品久久久www| 国产精品伊人久久伊人电影 | 国产69精品久久久久777| 久久久亚洲裙底偷窥综合 | 国产精品99久久久久久董美香| 国产V综合V亚洲欧美久久| 久久综合国产乱子伦精品免费| 伊人久久大香线蕉综合5g| 色婷婷久久综合中文久久一本| 久久久精品人妻无码专区不卡| 777久久精品一区二区三区无码| 国产精品久久免费| 久久这里只有精品首页| 久久99久久无码毛片一区二区| 国产精品久久久久乳精品爆|