FZU 1502 Letter Deletion
2009-12-13 19:57
204 查看
Accept: 174 Submit: 398
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
You are given two words (each word consists of upper-case English letters).Try to delete some letters from each word so that the resulting words are equal.
What is the maximum possible length of the resulting word?
Input
There will be no more than 10 test cases.Each test case consists of a single line, contaning the two 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 that can be created from both words by removing some letters).If the two words have no letters in common, output 0.
Sample Input
AAABBB ABABABAXYAAZ CCCXCCCYCCCZCC
ABCDE EDCBA
Sample Output
43
1
//动态规划题;
#include<iostream> using namespace std; int c[201][201]; char x[201],y[201]; void LCSLength(int m,int n) { int i,j; for(i=1;i<=m;i++) for(j=1;j<=n;j++) { if(x[i-1]==y[j-1]) c[i][j]=c[i-1][j-1]+1; else if(c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j]; else c[i][j]=c[i][j-1]; } } int main() { int n,m; while(scanf("%s%s",x,y)!=EOF) { memset(c,0,sizeof(c)); m=strlen(x); n=strlen(y); LCSLength(m,n); cout<<c[m] <<endl; } return 0; }
相关文章推荐
- FZU 1502 Letter Deletion
- FZU 1502 Letter Deletion
- FZU 1502 Letter Deletion
- Fzu 1752 A^B mod C【快速幂+快速积+细节处理】
- FZU 1896 神奇的魔法数 数位DP
- FZU 2213 Common Tangents 第六届福建省赛
- FZU 2195 检查站点
- [FZU 2142 Center of a Tree] 树形DP
- FZU 1021 飞船赛
- FZU Problem 2244 Daxia want to buy house
- [FZU 2105 Digits Count] 线段树区间的复合操作
- 解题报告:FZU1692 Key problem 循环矩阵快速幂
- FZU 2111 Min Number
- FZU Problem 2232 炉石传说(匈牙利算法)
- FZU 2186 BFS+状压(类似TSP)
- FZU 2184 逆序数还原
- FZU Problem 2140 Forever 0.5(计算几何构造,依旧考查思维)
- FZU 2082(过路费)
- 厂用电继电保护整定计算导则 DL/T 1502 - 2016
- FZU--2150 Fire Game(一道出乎意料的搜索)