• <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 閱讀(493) 評論(0)  編輯 收藏 引用
            久久婷婷人人澡人人| 久久精品国产精品国产精品污 | 天天影视色香欲综合久久| 久久乐国产综合亚洲精品| 77777亚洲午夜久久多喷| 国产精品一久久香蕉产线看| 久久99精品国产麻豆蜜芽| 久久人人爽人人爽人人片AV不| 精品人妻久久久久久888| 久久无码精品一区二区三区| 久久亚洲sm情趣捆绑调教| 国产AV影片久久久久久| 久久久久亚洲AV成人片| 久久综合狠狠综合久久97色| 国产精品久久久久aaaa| 一本一道久久综合狠狠老| 久久久WWW免费人成精品| 精品免费tv久久久久久久| 人妻无码中文久久久久专区| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 国产精品99久久精品爆乳| 久久99精品久久久久久hb无码 | 午夜欧美精品久久久久久久| 亚洲国产精品无码久久久久久曰| 精品综合久久久久久97超人| 老色鬼久久亚洲AV综合| 久久精品国产乱子伦| 日韩精品无码久久一区二区三| 久久国产成人午夜aⅴ影院 | 亚洲精品乱码久久久久66| 欧美亚洲国产精品久久| 尹人香蕉久久99天天拍| 伊人久久成人成综合网222| 午夜精品久久久久久影视777| 久久AⅤ人妻少妇嫩草影院| 久久精品免费网站网| 欧美成a人片免费看久久| 欧美精品福利视频一区二区三区久久久精品 | 91亚洲国产成人久久精品网址| 久久精品成人国产午夜| 国产亚州精品女人久久久久久|