• <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 閱讀(327) 評論(0)  編輯 收藏 引用
            <2009年4月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            常用鏈接

            留言簿(8)

            隨筆檔案

            文章檔案

            Friends

            OJ

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品aⅴ无码中文字字幕重口| 久久综合久久性久99毛片| 久久婷婷五月综合国产尤物app| 无码专区久久综合久中文字幕 | 欧美午夜A∨大片久久 | 久久久久久久国产免费看| 亚洲国产日韩欧美久久| 伊人久久大香线蕉亚洲五月天| 久久久亚洲欧洲日产国码aⅴ| 国产A级毛片久久久精品毛片| 狠狠色丁香久久婷婷综合图片| 精品综合久久久久久888蜜芽| 久久国产色AV免费看| 青青草原综合久久大伊人| 久久精品人人做人人爽97| 久久精品国产精品亚洲精品| 国产成人精品久久综合| 久久精品中文无码资源站| 久久久久亚洲AV无码专区桃色| 久久人人添人人爽添人人片牛牛| 亚洲中文字幕无码一久久区| 7777精品久久久大香线蕉 | 伊人久久大香线蕉综合5g| 国产999精品久久久久久| 久久人与动人物a级毛片| 国内精品久久久久影院薰衣草 | 久久夜色精品国产噜噜亚洲AV| 一本色综合久久| 国产91久久精品一区二区| 久久久亚洲欧洲日产国码aⅴ | 久久精品国产一区二区| 女同久久| segui久久国产精品| 伊色综合久久之综合久久| 国产亚洲精久久久久久无码| 91精品国产9l久久久久| 一本大道久久a久久精品综合| 久久亚洲AV永久无码精品| 夜夜亚洲天天久久| 久久99精品久久久久子伦| 亚洲午夜无码久久久久小说|