• <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 閱讀(215) 評論(0)  編輯 收藏 引用 所屬分類: B_搜索

            導航

            <2010年7月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品二区| 久久精品成人免费国产片小草| 久久综合偷偷噜噜噜色| 中文字幕无码久久精品青草| 伊色综合久久之综合久久| 久久久久久久久久久久中文字幕| 久久国产乱子伦精品免费强| 色婷婷噜噜久久国产精品12p| 国产成人精品综合久久久久| 99久久精品国产高清一区二区| 久久综合九色综合久99| 亚洲午夜久久久久久久久电影网| 国内精品久久九九国产精品| 欧美性大战久久久久久| 国内精品久久九九国产精品| 亚洲欧洲精品成人久久奇米网| 久久久久亚洲av无码专区导航| 亚洲国产成人精品无码久久久久久综合| 久久精品国产亚洲av麻豆蜜芽 | 伊人久久无码精品中文字幕| 久久久久久久久久久久中文字幕| 久久亚洲欧洲国产综合| 91精品久久久久久无码| 久久91综合国产91久久精品| 久久精品免费一区二区| 麻豆精品久久久久久久99蜜桃| 国产精品va久久久久久久| 97久久久精品综合88久久| 97久久国产露脸精品国产| 国产99久久久国产精品小说| 久久精品无码一区二区三区免费| 94久久国产乱子伦精品免费 | 久久婷婷五月综合色奶水99啪| 久久精品国产一区二区三区不卡| 日本久久久精品中文字幕| 久久精品国产只有精品2020| 亚洲国产精品久久电影欧美| 欧美精品久久久久久久自慰| 97久久久久人妻精品专区| 精品一区二区久久| 777久久精品一区二区三区无码|