HDU 1159 Common Subsequence

题解:裸的LCS

HDU 1159 Common Subsequence
/*LCS*/
#include <iostream>
#include <string>
using namespace std;
int f[1000][1000]={0};
int main()
{
    string a,b;
    while(cin>>a>>b)
    {
        int m,n;
        n=a.length();
        m=b.length();
        memset(f,0,sizeof(f));
        for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)
        {
            if (a[i]==b[j]) f[i+1][j+1]=f[i][j]+1;
            else (f[i][j+1]>f[i+1][j])?f[i+1][j+1]=f[i][j+1]:f[i+1][j+1]=f[i+1][j];
        }
        printf("%d\n",f[n][m]);
    }
    return 0; 
}
HDU 1159 Common Subsequence

HDU 1159 Common Subsequence

上一篇:ConfigurationManager配置操作


下一篇:bing 比赛部分代码