• <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 閱讀(479) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            精品人妻伦一二三区久久| 色偷偷久久一区二区三区| 久久香蕉国产线看观看乱码| 69久久精品无码一区二区| 色综合久久中文综合网| 久久精品无码免费不卡| 伊人久久大香线蕉综合5g| 久久精品人人做人人爽电影蜜月| 国产精品美女久久久免费| 久久中文字幕人妻丝袜| 嫩草影院久久国产精品| 99久久国产亚洲综合精品| 香蕉久久一区二区不卡无毒影院| 欧美成a人片免费看久久| 狠狠88综合久久久久综合网 | 色欲久久久天天天综合网精品| 丰满少妇高潮惨叫久久久| 欧美麻豆久久久久久中文| 99麻豆久久久国产精品免费| 精品久久久久成人码免费动漫| 久久国产精品久久国产精品| 久久精品国产久精国产一老狼| 99久久精品国产一区二区| 国产V亚洲V天堂无码久久久| 伊人久久亚洲综合影院| 久久精品国产第一区二区| 91精品国产综合久久四虎久久无码一级| 久久久久久精品免费看SSS | 亚洲人成无码网站久久99热国产| 久久久久亚洲精品天堂| 精品人妻伦九区久久AAA片69| 久久精品成人一区二区三区| 青青国产成人久久91网| 久久久久久久综合日本亚洲| 久久亚洲欧美国产精品| 欧美午夜精品久久久久免费视| 久久亚洲精品无码aⅴ大香 | 色欲久久久天天天综合网精品| 久久天天躁狠狠躁夜夜2020一| 日韩欧美亚洲综合久久| 久久伊人精品一区二区三区|