• <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 1080 Human Gene Functions

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

            思路:
            想法與最長公共子序列類似
            用f[i][j]表示str_a[1..i]與str_b[1..j]的相似度,而所求即f[len_a][len_b],需要注意初始化部分的代碼
            狀態轉移方程見代碼注釋

            代碼:
             1 #include<stdio.h>
             2 #include<stdlib.h>
             3 #include<string.h>
             4 #define MAX_LEN 101
             5 #define INF 'I'
             6 #define Score(ch_a, ch_b) (score[map[ch_a-'A']][map[ch_b-'A']])
             7 int len_a, len_b;
             8 char str_a[MAX_LEN+1], str_b[MAX_LEN+1];
             9 int table[MAX_LEN][MAX_LEN];
            10 const int score[][5= {{5,-1,-2,-1,-3}, {-1,5,-3,-2,-4}, {-2,-3,5,-2,-2}, {-1,-2,-2,5,-1}, {-3,-4,-2,-1,-65535}};
            11                               /* A    C          G    I                               T */  
            12 const int map[] = {0,-1,1,-1,-1,-1,2,-1,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3};
            13 
            14 /*
            15  * f[i][j] represent the similarity of str_a[1..i] and str_b[1..j], so:
            16  *    f[i][j] = max { f[i-1][j-1]+Score(str_a[i], str_b[j]), 
            17  *                    f[i-1][j] + Score(str_a[i], '-'),
            18  *                    f[i][j-1] + Score('-', str_b[j]) }
            19  */
            20 int
            21 dp()
            22 {
            23     int i, j, a, b, c, max;
            24     /* Attention: Initialization */
            25     table[0][0= 0;
            26     for(i=1; i<=len_a; i++)
            27         table[i][0= table[i-1][0+ Score(str_a[i], INF);
            28     for(j=1; j<=len_b; j++)
            29         table[0][j] = table[0][j-1+ Score(str_b[j], INF);
            30     
            31     for(i=1; i<=len_a; i++) {
            32         for(j=1; j<=len_b; j++) {
            33             a = table[i-1][j-1+ Score(str_a[i], str_b[j]);
            34             b = table[i-1][j] + Score(str_a[i], INF);
            35             c = table[i][j-1+ Score(INF, str_b[j]);
            36             max = a > b ? a : b;
            37             max = c > max ? c : max;
            38             table[i][j] = max;
            39         }
            40     }
            41     return table[len_a][len_b];
            42 }
            43 
            44 int
            45 main(int argc, char **argv)
            46 {
            47     int tests;
            48     scanf("%d"&tests);
            49     while(tests--) {
            50         scanf("%d %s"&len_a, str_a+1);
            51         scanf("%d %s"&len_b, str_b+1);
            52         printf("%d\n", dp());
            53     }
            54 }

            posted on 2010-08-13 14:07 simplyzhao 閱讀(126) 評論(0)  編輯 收藏 引用 所屬分類: C_動態規劃

            導航

            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久久久波多野结衣高潮| 久久综合丁香激情久久| 大蕉久久伊人中文字幕| 久久精品成人免费网站| 狠狠色丁香婷婷久久综合五月| 国内精品伊人久久久久| 精品久久人妻av中文字幕| 亚洲国产成人精品女人久久久 | 亚洲国产成人久久精品99 | 久久精品亚洲福利| 日韩亚洲国产综合久久久| 亚洲狠狠综合久久| 国产精品一区二区久久| 狠狠色丁香婷综合久久| 中文字幕日本人妻久久久免费| 久久se精品一区二区| 激情伊人五月天久久综合| 久久综合偷偷噜噜噜色| 久久综合亚洲鲁鲁五月天| 久久这里只精品99re66| 日本五月天婷久久网站| 久久久久久久综合狠狠综合| 99久久综合国产精品二区| 久久99久久无码毛片一区二区| 伊色综合久久之综合久久| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 日本三级久久网| 久久WWW免费人成—看片| 免费精品久久久久久中文字幕| 无码人妻精品一区二区三区久久| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久综合久久综合亚洲| 丰满少妇高潮惨叫久久久| 久久久av波多野一区二区| 久久国产精品99久久久久久老狼| 狠狠狠色丁香婷婷综合久久五月| 久久精品免费一区二区| 欧美日韩中文字幕久久久不卡| 久久中文字幕人妻丝袜| 伊人久久无码精品中文字幕| 99re久久精品国产首页2020|