• <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>
            posts - 74,  comments - 33,  trackbacks - 0
            Cell Phone Network
            Time Limit: 1000MS Memory Limit: 65536K
            Total Submissions: 1440 Accepted: 443

            Description

            Farmer John has decided to give each of his cows a cell phone in hopes to encourage their social interaction. This, however, requires him to set up cell phone towers on his N (1 ≤ N ≤ 10,000) pastures (conveniently numbered 1..N) so they can all communicate.

            Exactly N-1 pairs of pastures are adjacent, and for any two pastures A and B (1 ≤ AN; 1 ≤ BN; AB) there is a sequence of adjacent pastures such that A is the first pasture in the sequence and B is the last. Farmer John can only place cell phone towers in the pastures, and each tower has enough range to provide service to the pasture it is on and all pastures adjacent to the pasture with the cell tower.

            Help him determine the minimum number of towers he must install to provide cell phone service to each pasture.

            Input

            * Line 1: A single integer: N
            * Lines 2..N: Each line specifies a pair of adjacent pastures with two space-separated integers: A and B

            Output

            * Line 1: A single integer indicating the minimum number of towers to install

            Sample Input

            5
            1 3
            5 2
            4 3
            3 5
            

            Sample Output

            2
            

            Source

            USACO 2008 January Gold
            今天軟件工程的時候想通了這道題目成功的把3中狀態和DP聯系起來,以前思考的時候一直從root想leaves執行程序,而下午仔細想想如果從root出發,而執行程序的時候無法統計最后的點數,更可怕的是不是root影響leaves而是leaves影響著root的取值達到最優值!而這道題就是這樣可以計算下利用DFS遍歷Tree我們知道DFS時間度為O(n)空間上用鄰接表記錄關系圖,O(n)
            說下3中狀態轉移,我就不講了,我這人口才不好,看寫的比說的清楚,哈哈~~
            第一種狀態:就是一個節點不放置塔,而它的所有leaves被覆蓋,當然它自己能被它的leaves控制。
            第二種狀態:一個節點和它的所有leaves全被覆蓋,而這個節點放置控制塔。
            第三種狀態:一個節點暫時沒有被覆蓋,也沒有放置節點。
            DFS函數如下:
            void?DFS(int?x){
            ????
            int?i,sign,flag;
            ????
            for(flag=sign=i=0;i<v[x].size();i++){
            ????????
            int?t=v[x][i];
            ???????????
            if(!mark[t]){
            ????????????sign
            =1;mark[t]=1;
            ????????????DFS(v[x][i]);
            ????????????
            if(dp[t][0]<dp[t][1])dp[x][0]+=dp[t][0];
            ?????????????
            else?{
            ??????????????????dp[x][
            0]+=dp[t][1];
            ??????????????????sign
            =1;
            ?????????????}

            ?????????????dp[x][
            1]+=getmin(getmin(dp[t][0],dp[t][1]),dp[t][2]);
            ?????????????dp[x][
            2]+=dp[t][0];
            ???????????}

            ????}

            ????
            if(!sign)dp[x][0]=dp[x][1]=1;
            ????
            else{
            ????????dp[x][
            1]++;
            ???????????
            if(!flag)dp[x][0]+=1;
            ????}

            }
            posted on 2009-04-09 21:45 KNIGHT 閱讀(318) 評論(0)  編輯 收藏 引用
            <2009年4月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            常用鏈接

            留言簿(8)

            隨筆檔案

            文章檔案

            Friends

            OJ

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久高潮一级毛片免费| 久久91精品国产91| 国内精品九九久久久精品| 亚洲国产精品无码久久久秋霞2 | 性做久久久久久免费观看| 99热热久久这里只有精品68| 久久亚洲AV无码西西人体| 久久精品国产亚洲AV久| 欧美一区二区精品久久| 久久精品日日躁夜夜躁欧美| 九九99精品久久久久久| 久久久久久午夜精品| 久久99国产精品久久99| 国内精品久久久久影院亚洲| 91久久精品国产91性色也| 人妻无码精品久久亚瑟影视| 色成年激情久久综合| 亚洲国产欧美国产综合久久| 成人a毛片久久免费播放| 久久精品人人槡人妻人人玩AV | 一本大道加勒比久久综合| 中文字幕无码久久人妻| 99久久精品无码一区二区毛片| 亚洲精品高清国产一线久久| 久久国产精品偷99| 久久中文娱乐网| 久久er热视频在这里精品| 亚洲乱码精品久久久久..| 怡红院日本一道日本久久| 99精品国产在热久久无毒不卡| 久久精品国产AV一区二区三区| 久久久久这里只有精品| 国产成人综合久久精品尤物| 青青青青久久精品国产| 久久福利青草精品资源站免费| 国产亚洲精久久久久久无码| 精品综合久久久久久888蜜芽| 国内精品伊人久久久久av一坑| 欧美一区二区三区久久综合 | 麻豆精品久久精品色综合| 久久精品国产免费一区|