• <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)  編輯 收藏 引用
            国产成人精品久久| 久久精品国产亚洲AV嫖农村妇女| 国产成年无码久久久久毛片| 婷婷综合久久中文字幕蜜桃三电影| 久久精品成人免费观看97| 国内精品久久国产大陆| 国产精品午夜久久| 久久青青色综合| 久久99精品国产麻豆宅宅| 久久中文字幕精品| 国产精品久久久久国产A级| 成人a毛片久久免费播放| 亚洲国产精品18久久久久久| 色噜噜狠狠先锋影音久久| 无码任你躁久久久久久老妇App| 久久99国产精品久久久| 亚洲欧美另类日本久久国产真实乱对白| 色欲综合久久躁天天躁蜜桃| 色成年激情久久综合| 亚洲欧洲日产国码无码久久99| 亚洲狠狠久久综合一区77777| 国产精品久久久久久久久久影院| 国产精品狼人久久久久影院| 亚洲精品乱码久久久久久蜜桃不卡| 久久免费国产精品| 中文字幕成人精品久久不卡 | 久久偷看各类wc女厕嘘嘘| 国产日韩欧美久久| www.久久热.com| 精品无码久久久久久午夜| 伊人久久大香线蕉av一区| 久久伊人亚洲AV无码网站| 久久www免费人成看国产片 | 国产精品免费久久久久久久久| 久久国产精品成人片免费| 一本久道久久综合狠狠爱| 97视频久久久| 精品人妻伦九区久久AAA片69| 久久精品综合网| 久久国产精品无| 午夜精品久久久久久久久|