• <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 閱讀(487) 評論(0)  編輯 收藏 引用
            国产精品18久久久久久vr | 日本福利片国产午夜久久| 国产V综合V亚洲欧美久久| 伊人久久大香线蕉影院95| 伊人色综合久久天天人守人婷 | 久久男人Av资源网站无码软件| 久久婷婷久久一区二区三区| 国产高潮国产高潮久久久91 | 狠狠狠色丁香婷婷综合久久俺| 久久国产午夜精品一区二区三区| 亚洲欧美成人久久综合中文网| 亚洲精品蜜桃久久久久久| 久久性精品| 精品久久久久久无码人妻蜜桃| 人妻无码中文久久久久专区| 亚洲日本va午夜中文字幕久久| 久久国产精品成人影院| 国产午夜电影久久| 色综合久久久久综合体桃花网| 久久人搡人人玩人妻精品首页| 国产91久久精品一区二区| 亚洲欧美久久久久9999| segui久久国产精品| 1000部精品久久久久久久久| 伊人久久大香线焦AV综合影院 | 欧美亚洲国产精品久久高清| 久久99精品九九九久久婷婷| 国内精品久久久人妻中文字幕| 久久久久亚洲AV成人网人人网站 | 青青青国产成人久久111网站| 亚洲国产精品无码久久久秋霞2| 欧美精品丝袜久久久中文字幕| 97久久精品人人澡人人爽| 精品久久久久久| 久久电影网一区| 久久99国产精品久久99| 97久久精品无码一区二区| 99久久精品国产高清一区二区 | 99久久精品国产麻豆| 久久se精品一区二区| 久久久久久免费一区二区三区|