
正文
解题报告:hdu1159 common consequence LCS裸题
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
2017-09-02 17:07:42
writer:pprp
通过这个题温习了一下刚学的LCS
代码如下:
/*
@theme:hdu1159
@writer:pprp
@begin:17:01
@end:17:06
@declare:LCS的裸题,温习一下
@error:从1开始读入的话,用strlen也要从1开始测才可以
@date:2017/9/2
*/ #include <bits/stdc++.h> using namespace std; char s1[],s2[];
int dp[][];
int main()
{ //freopen("in.txt","r",stdin);
while(~scanf("%s%s",s1+,s2+))
{
memset(dp,,sizeof(dp));
int n = strlen(s1+);
int m = strlen(s2+); for(int i = ; i <= n ;i++)
{
for(int j = ; j <= m ; j++)
{
if(s1[i] == s2[j])
dp[i][j] = dp[i-][j-] + ;
else
dp[i][j] = max(dp[i-][j],dp[i][j-]);
}
}
cout << dp[n][m] << endl;
} return ;
}







