• <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)  編輯 收藏 引用
            久久亚洲国产成人影院网站| 色婷婷噜噜久久国产精品12p| 狠狠综合久久AV一区二区三区| 亚洲色欲久久久久综合网| 人妻精品久久久久中文字幕69| 精品国产福利久久久| 亚洲国产一成久久精品国产成人综合| 亚洲综合精品香蕉久久网| 国产精品久久久久乳精品爆| 精品国产乱码久久久久久人妻| 99久久综合狠狠综合久久| 亚洲成色WWW久久网站| 久久99热国产这有精品| 国产成人无码精品久久久性色 | 久久人妻无码中文字幕| 国产精品久久久福利| 久久久一本精品99久久精品88| 久久精品国产亚洲5555| 99久久精品国产免看国产一区| 久久精品国产亚洲av麻豆图片 | 久久亚洲AV成人无码| 欧美精品一区二区精品久久 | 99麻豆久久久国产精品免费| 久久这里都是精品| 久久久久综合中文字幕| 国产国产成人久久精品| 狠狠88综合久久久久综合网| 2019久久久高清456| 99久久人人爽亚洲精品美女| 99久久精品毛片免费播放| 国产精品久久午夜夜伦鲁鲁| 久久精品国产亚洲AV无码偷窥| 无码人妻少妇久久中文字幕蜜桃 | 久久久久18| 久久综合九色欧美综合狠狠| 精品无码人妻久久久久久| 精品久久人人妻人人做精品| 国产69精品久久久久9999| 久久av高潮av无码av喷吹| 日产久久强奸免费的看| 久久精品中文字幕大胸|