• <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 閱讀(484) 評論(0)  編輯 收藏 引用
            色天使久久综合网天天| 色88久久久久高潮综合影院| 国产亚洲精久久久久久无码AV| 国産精品久久久久久久| 伊人伊成久久人综合网777| 国产精品久久午夜夜伦鲁鲁| 亚洲欧美另类日本久久国产真实乱对白 | 91精品国产综合久久香蕉 | 91麻精品国产91久久久久 | 久久综合狠狠色综合伊人| 久久人人爽人人爽人人片av麻烦 | 久久乐国产综合亚洲精品| 99久久99久久精品国产片| 99精品久久精品一区二区| 久久AV高潮AV无码AV| 久久99精品综合国产首页| 免费国产99久久久香蕉| 久久精品国产精品亚洲精品| 国内精品久久久久久久久| 97精品国产91久久久久久| 精品久久一区二区| 97精品国产97久久久久久免费| 久久线看观看精品香蕉国产| 麻豆亚洲AV永久无码精品久久| 久久精品国产精品亚洲人人| 久久免费香蕉视频| 国产精品久久久久a影院| 思思久久99热免费精品6| 99久久精品无码一区二区毛片 | 99国内精品久久久久久久| 亚洲精品乱码久久久久久中文字幕 | 日韩欧美亚洲综合久久影院d3| 久久夜色精品国产噜噜麻豆 | 午夜精品久久久久久99热| 亚洲精品无码久久不卡| 久久亚洲国产精品五月天婷| 国产亚洲美女精品久久久| 国产精品99久久精品爆乳| 人妻系列无码专区久久五月天| 91久久精品电影| 久久99精品久久久久久噜噜|