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

            堅(jiān)信:勤能補(bǔ)拙

            PKU 1080 Human Gene Functions

            問(wèn)題:
            http://acm.pku.edu.cn/JudgeOnline/problem?id=1080

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

            代碼:
             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 閱讀(127) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C_動(dòng)態(tài)規(guī)劃

            導(dǎo)航

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

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久超乳爆乳中文字幕| 欧美激情精品久久久久久久九九九 | 久久精品国产亚洲AV无码麻豆| 波多野结衣久久精品| 久久无码人妻一区二区三区午夜| 狠狠色婷婷久久一区二区三区 | 久久久精品人妻一区二区三区蜜桃| 精品国产99久久久久久麻豆| 国产精品99精品久久免费| 狠狠色综合久久久久尤物| 久久国产精品无| 91久久婷婷国产综合精品青草 | 久久青青色综合| 97精品伊人久久大香线蕉app| 久久国产美女免费观看精品| 东方aⅴ免费观看久久av| 久久香蕉国产线看观看99| 亚洲&#228;v永久无码精品天堂久久 | 91精品国产91久久久久福利| 精品久久久久一区二区三区| 日产精品久久久一区二区| 色偷偷88欧美精品久久久| 久久99国产精品久久| 精品多毛少妇人妻AV免费久久 | 久久综合色老色| 久久综合九色综合久99| 99久久精品午夜一区二区| 狠狠色丁香久久婷婷综合图片| 91精品国产91久久久久久| 久久人爽人人爽人人片AV| 久久精品卫校国产小美女| 久久亚洲国产最新网站| 国产午夜精品久久久久九九电影| 久久99亚洲网美利坚合众国| 99精品国产综合久久久久五月天| 蜜桃麻豆www久久国产精品| 国产免费久久久久久无码| 国产精品综合久久第一页| 99久久亚洲综合精品网站| 国产福利电影一区二区三区久久久久成人精品综合 | 2021久久精品免费观看|