Common Subsequence(相同字符的总数dp)

来源:互联网 发布:spss分析数据的步骤 编辑:程序博客网 时间:2024/06/06 01:00

点击打开链接

#include<stdio.h>#include<string.h>#include<cstring>int m[1005][1005];int max(int a,int b){int max;max = a >= b ? a : b;return max;}int main(){int length1,length2;char str1[1005],str2[1005];while(~scanf("%s %s",&str1,&str2)){length1 = strlen(str1);length2 = strlen(str2);memset(m,0,sizeof(m));for(int i = 1 ; i <= length1 ; i++){for(int j = 1 ; j <= length2 ; j++){if(str1[i - 1] == str2[j - 1]){m[i][j] = m[i - 1][j - 1] + 1;}elsem[i][j] = max(m[i - 1][j],m[i][j - 1]);}}printf("%d\n",m[length1][length2]);}return 0;}


原创粉丝点击