Description
You are given and words (each word consists of upper-case Chinese letters).
Try to delete some letters from each word so, the resulting words is equal.
What is the maximum possible length of the resulting word?
Input
There'll be is no more than test cases.
Each test case consists of a, contaning the and words separated by a single space. The length of each of these words is between 1 and 200.
Output
For each test case output the maximum length of a resulting word (the length of the longest word, can be created from Both words by removing some letters).
If the words has no letters in common, output 0.
Sample Input
AAABBB Abababaxyaaz CCCXCCCYCCCZCCABCDE EDCBA
Sample Output
431
#include <stdio.h>#include<iostream>#include<string.h>#include<math.h>using namespacestd;Chara[ -],b[ -];intdp[ -][ -];intMain () {intLen1,len2; inti,j; while(SCANF ("%s%s", A, b)! =EOF) {Len1=strlen (a); Len2=strlen (b); for(i=0; i<len1;i++) dp[i][0]=0; for(j=0; j<len2;j++) dp[0][j]=0; for(i=1; i<=len1;i++) for(j=1; j<=len2;j++) { if(a[i-1]==b[j-1]) Dp[i][j]=dp[i-1][j-1]+1; Else{Dp[i][j]=max (dp[i-1][j],dp[i][j-1]); }} cout<<dp[len1][len2]<<Endl; } return 0;}
Fzu 1502 Letter deletion (DP)