• <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>

            A Za, A Za, Fighting...

            堅信:勤能補拙

            PKU 1129 Channel Allocation

            問題:
            http://acm.pku.edu.cn/JudgeOnline/problem?id=1129

            思路:
            好題,典型的圖著色問題
            首先,對于鄰接關(guān)系,可以用二維數(shù)組來表示
            具有鄰接關(guān)系的節(jié)點不能使用同一種顏色,求所需顏色的最小值
            深度優(yōu)先搜索,當目前使用顏色個數(shù)已經(jīng)超過當前最優(yōu)解時進行減枝

            代碼:
             1 #define MAX_NUM 29
             2 #define INF 100000
             3 int graph[MAX_NUM][MAX_NUM];
             4 int color[MAX_NUM];
             5 int num, ans;
             6 
             7 void
             8 init()
             9 {
            10     int i, j, len;
            11     char conn[MAX_NUM];
            12     memset(graph, 0sizeof(graph));
            13     memset(color, -1sizeof(color));
            14     ans = INF;
            15     for(i=0; i<num; i++) {
            16         scanf("%s", conn);
            17         len = strlen(conn);
            18         for(j=2; j<len; j++)
            19             graph[i][conn[j]-'A'= 1;
            20     }
            21 }
            22 
            23 int
            24 is_valid(int depth, int cindex)
            25 {
            26     int i;
            27     for(i=0; i<depth; i++)
            28         if(graph[depth][i] && color[i]==cindex)
            29             return 0;
            30     return 1;
            31 }
            32 
            33 void 
            34 dfs(int depth, int used_colors)
            35 {
            36     int i;
            37     if(used_colors >= ans) /* pruning */
            38         return;
            39     if(depth == num) {
            40         ans = used_colors<ans ? used_colors : ans;
            41         return;
            42     }
            43     for(i=1; i<=used_colors; i++) {
            44         if(is_valid(depth, i)) {
            45             color[depth] = i;
            46             dfs(depth+1, used_colors);
            47             color[depth] = -1;
            48         }
            49     }
            50     color[depth] = used_colors+1;
            51     dfs(depth+1, used_colors+1);
            52     color[depth] = -1;
            53 }


            posted on 2010-07-26 20:47 simplyzhao 閱讀(221) 評論(0)  編輯 收藏 引用 所屬分類: B_搜索

            導(dǎo)航

            <2011年10月>
            2526272829301
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            国产成人久久久精品二区三区| 亚洲人成精品久久久久| 无码任你躁久久久久久| 久久精品国产色蜜蜜麻豆| 久久天天躁狠狠躁夜夜2020老熟妇| 日本加勒比久久精品| 一本大道久久a久久精品综合| 国产69精品久久久久APP下载 | 久久久国产精品网站| 国产精品久久婷婷六月丁香| 国产99久久九九精品无码| 国产精品美女久久久| 99麻豆久久久国产精品免费 | 久久久久国产日韩精品网站| 久久综合给合久久狠狠狠97色69| 久久不见久久见免费影院www日本| 国产成年无码久久久久毛片| 午夜精品久久久久久99热| 亚洲精品无码久久久久| 久久精品国产亚洲网站| 久久妇女高潮几次MBA| 久久午夜电影网| 国产福利电影一区二区三区,免费久久久久久久精| 中文字幕久久欲求不满| 人妻丰满?V无码久久不卡| 久久久久免费看成人影片| 狠狠色丁香久久婷婷综| 亚洲人AV永久一区二区三区久久| 狠狠色丁香久久综合婷婷| 久久亚洲精品成人AV| 久久精品国产99国产精品导航| 亚洲国产成人久久综合区| 久久久久国产| 亚洲精品综合久久| 欧美亚洲国产精品久久久久| 少妇久久久久久被弄到高潮| 亚洲AV伊人久久青青草原| 国产精品久久久久免费a∨| 久久精品中文无码资源站| 久久精品99久久香蕉国产色戒 | 久久国产成人精品麻豆|