标签:
Common Subsequence
Time Limit: 2 Sec Memory Limit: 64 MB
Submit: 951 Solved: 374
abcfbc abfcab programming contest abcd mnp
4 2 0
1 #include<stdio.h> 2 #include<string.h> 3 #define Max( a, b ) (a) > (b) ? (a) : (b) 4 5 char s1[1005], s2[1005]; 6 7 int dp[1005][1005]; 8 9 int main() 10 { 11 int len1, len2; 12 while( scanf( "%s %s", s1+1, s2+1 ) != EOF ) 13 { 14 memset( dp, 0, sizeof(dp) ); 15 len1 = strlen( s1+1 ), len2 = strlen( s2+1 ); 16 for( int i = 1; i <= len1; ++i ) 17 { 18 for( int j = 1; j <= len2; ++j ) 19 { 20 if( s1[i] == s2[j] ) 21 { 22 dp[i][j] = dp[i-1][j-1] + 1; 23 } 24 else 25 { 26 dp[i][j] = Max ( dp[i-1][j], dp[i][j-1] ); 27 } 28 } 29 } 30 printf( "%d\n", dp[len1][len2] ); 31 } 32 return 0; 33 }
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4198474.html