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

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久亚洲精品成人无码网站| 亚洲国产精品成人久久蜜臀| 久久精品国产亚洲av瑜伽| 久久人人爽人人爽人人AV东京热 | 精品无码久久久久久久动漫| 久久精品天天中文字幕人妻| 久久综合香蕉国产蜜臀AV| 日韩AV无码久久一区二区 | 97久久精品人妻人人搡人人玩| 人妻精品久久无码专区精东影业 | 久久91精品综合国产首页| 日本福利片国产午夜久久| 国产精品午夜久久| 精品久久久久久无码不卡| 性做久久久久久久| 久久精品人人做人人爽电影| 国产69精品久久久久9999| 欧美激情精品久久久久久久九九九| 狠狠色丁香婷婷久久综合 | 精品久久一区二区| 久久久久国产一区二区| 久久精品国产欧美日韩99热| 国产人久久人人人人爽| 久久电影网2021| 久久亚洲国产精品成人AV秋霞| 高清免费久久午夜精品| 精品人妻伦一二三区久久| 无码伊人66久久大杳蕉网站谷歌| 国产精品岛国久久久久| 日韩欧美亚洲综合久久影院Ds| 日产精品99久久久久久| 久久久国产精华液| 国产成人综合久久综合| 日本亚洲色大成网站WWW久久 | 久久久无码精品亚洲日韩京东传媒| 国内精品久久久久影院日本| 久久伊人中文无码| 久久精品国产91久久综合麻豆自制 | 久久热这里只有精品在线观看| 一本一道久久综合狠狠老| 久久99国产精品久久99|