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

            最小公共子序列

            Longest Common Subsequence

            Problem

            Given a sequence A = < a1, a2, ..., am >, let sequence B = < b1, b2, ..., bk > be a subsequence of A if there exists a strictly increasing sequence ( i1<i2<i3 ..., ik ) of indices of A such that for all j = 1,2,...,k, aij = bj. For example, B = < a, b, c, d > is a subsequence of A= < a, b, c, f, d, c > with index sequence < 1, 2, 3 ,5 >.
            Given two sequences X and Y, you need to find the length of the longest common subsequence of X and Y.

            Input

            The input may contain several test cases.

            The first line of each test case contains two integers N (the length of X) and M(the length of Y), The second line contains the sequence X, the third line contains the sequence Y, X and Y will be composed only from lowercase letters. (1<=N, M<=100)

            Input is terminated by EOF.

            Output

            Output the length of the longest common subsequence of X and Y on a single line for each test case.

            Sample input

            6 4
            abcfdc
            abcd
            2 2
            ab
            cd

            Sample output

            4
            0

            #include <stdio.h>
            char x[105],y[105];
            int c[109][109],i,j,leny,lenx;
            int main(){
                
            while(scanf("%d %d",&lenx,&leny)!=EOF){
                    scanf(
            "%s",&x);
                    scanf(
            "%s",&y);
                    
            for(i=0;i<=leny;i++)
                        c[
            0][i]=0;
                    
            for(i=1;i<=lenx;i++)
                        c[i][
            0]=0;
                    
            for(i=1;i<=lenx;i++){
                        
            for(j=1;j<=leny;j++){
                            
            if(x[i-1]==y[j-1])
                                c[i][j]
            =c[i-1][j-1]+1;
                            
            else{
                                
            if(c[i-1][j]>=c[i][j-1])
                                    c[i][j]
            =c[i-1][j];
                                
            else c[i][j]=c[i][j-1];
                            }

                        }

                    }

                    printf(
            "%d\n",c[lenx][leny]);
                }

                
            return 0;
            }

            posted on 2008-04-08 13:27 zhongguoa 閱讀(483) 評論(0)  編輯 收藏 引用
            久久久久久久97| 亚洲国产成人精品女人久久久 | 久久久久久国产精品无码下载 | 亚洲AV无一区二区三区久久 | 久久精品久久久久观看99水蜜桃 | 大香网伊人久久综合网2020| 欧美久久精品一级c片片| 精品国产综合区久久久久久| 一级做a爰片久久毛片毛片| 久久国产欧美日韩精品| 久久99精品国产麻豆婷婷| 亚洲国产日韩综合久久精品| 国内精品久久久久影院一蜜桃| 亚洲嫩草影院久久精品| 一本色道久久99一综合| Xx性欧美肥妇精品久久久久久| 国产成人精品综合久久久久 | 国产精品久久久久久福利69堂| 人妻无码久久精品| 久久亚洲高清观看| 性色欲网站人妻丰满中文久久不卡| 国产福利电影一区二区三区久久老子无码午夜伦不 | 亚洲欧美一区二区三区久久| 99久久精品费精品国产| 久久99热只有频精品8| 亚洲精品第一综合99久久| 久久久久久毛片免费看 | 久久久久久毛片免费看| 国产精品成人99久久久久91gav| 久久人人爽人人爽人人片av高请| 久久综合成人网| 久久精品亚洲福利| 久久久久久久综合综合狠狠| 国产成人无码精品久久久久免费| 精品无码久久久久久尤物| 成人午夜精品无码区久久| 久久久久久国产a免费观看黄色大片| 国产AⅤ精品一区二区三区久久| 欧美777精品久久久久网| 亚洲精品高清久久| 久久国产美女免费观看精品|