• <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) 評論(0)  編輯 收藏 引用
            午夜视频久久久久一区| 久久中文字幕精品| 午夜不卡久久精品无码免费| 久久精品国产亚洲AV蜜臀色欲| 综合人妻久久一区二区精品| 青青草国产精品久久久久| 久久精品国产一区二区电影| 一级做a爰片久久毛片看看| 国产精品美女久久久久网| 久久久精品日本一区二区三区 | 伊人久久大香线蕉AV一区二区| 国产午夜精品久久久久九九电影 | 亚洲Av无码国产情品久久| 免费精品久久天干天干| 精品无码人妻久久久久久| 少妇无套内谢久久久久| 亚洲精品高清久久| 久久91精品国产91久久麻豆| 麻豆一区二区99久久久久| 国产精品免费久久| 91久久精品视频| 午夜精品久久久久久中宇| 久久伊人五月天论坛| 久久久久久国产精品无码下载 | 99久久精品免费| 久久亚洲国产成人精品性色| 国内精品伊人久久久久影院对白| 亚洲成色www久久网站夜月| 久久久久久国产精品无码下载| 日本精品久久久久中文字幕8| 亚洲va久久久噜噜噜久久| 亚洲精品99久久久久中文字幕| 狠狠色丁香婷婷综合久久来| 久久亚洲精品国产精品| 亚洲国产精品无码久久一线| 九九精品久久久久久噜噜| 午夜视频久久久久一区| 久久精品国产99国产精品亚洲 | 久久中文字幕视频、最近更新| 伊人丁香狠狠色综合久久| 久久这里只精品国产99热|