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 ABABAB
AXYAAZ CCCXCCCYCCCZCC
ABCDE EDCBA

Sample Output

4
3
1
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
char a[],b[];
int dp[][];
int main()
{
int len1,len2;
int i,j;
while(scanf("%s%s",a,b)!=EOF)
{ len1=strlen(a);
len2=strlen(b);
for(i=;i<len1;i++)
dp[i][]=;
for(j=;j<len2;j++)
dp[][j]=;
for(i=;i<=len1;i++)
for(j=;j<=len2;j++)
{
if(a[i-]==b[j-])
dp[i][j]=dp[i-][j-]+;
else
{
dp[i][j]=max(dp[i-][j],dp[i][j-]);
}
}
cout<<dp[len1][len2]<<endl;
}
return ;
}

FZU 1502 Letter Deletion(DP)的更多相关文章

  1. FZU 1502 Letter Deletion

    最长公共子序列. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...

  2. FZU - 2204 简单环形dp

    FZU - 2204 简单环形dp 题目链接 n个有标号的球围成一个圈.每个球有两种颜色可以选择黑或白染色.问有多少种方案使得没有出现连续白球7个或连续黑球7个. 输入 第一行有多组数据.第一行T表示 ...

  3. FZU 1025 状压dp 摆砖块

    云峰菌曾经提到过的黄老师过去讲课时的摆砖块 那时百度了一下题目 想了想并没有想好怎么dp 就扔了 这两天想补动态规划知识 就去FZU做专题 然后又碰到了 就认真的想并且去做了 dp思想都在代码注释里 ...

  4. HDU 1502 Regular Words DP+高精度

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1502 题目大意:找出总的满足条件的字符串数,num(a)=num(b)=num(c)且任何前缀均满足n ...

  5. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) Letter(DP 枚举)

    Letter time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  6. FZU 2092 收集水晶 dp+bfs

    定义dp[t][x1][y1][x2][y2]为在t时刻,人走到x1,y1,影子走到x2,y2所获得最大价值 最终就是所有的dp[max][..][..][..][..]的最大值 然后递推也很自然,枚 ...

  7. FZU 2113(数位dp)

    题目连接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=38054 题意:求区间[a,b]中包含'1'的个数. 分析:数位dp ...

  8. FZU 1977 Pandora adventure (DP)

    题意:给定一个图,X表示不能走,O表示必须要走,*表示可走可不走,问你多少种走的法,使得形成一个回路. 析: 代码如下: #pragma comment(linker, "/STACK:10 ...

  9. Codeforces 180C Letter:dp

    题目链接:http://codeforces.com/problemset/problem/180/C 题意: 给你一个字符串s,长度为n. 让你将这个字符串变成“前面一段都是大写字母,后面一段都是小 ...

随机推荐

  1. http服务 Web API的使用

    http服务 Web API的使用 一.概念: Web API是网络应用程序接口. 详情百度百科: http://baike.baidu.com/link?url=X1l2dlU9FlQmupX24- ...

  2. WIN10使用管理员权限运行VS2013

    学习WCF时出现报错-- 其他信息: HTTP 无法注册 URL http://+:8083/User/.进程不具有此命名空间的访问权限(有关详细信息,请参见 http://go.microsoft. ...

  3. Prefix the choice with ! to persist it to bower.json ? Answer (问你选择哪个1,2,3.........)

    Unable to find a suitable version for underscore, please choose one by typing on e of the numbers be ...

  4. iOS 10 之后,相机权限问题及易出现的Crash

    1: iOS 10 之后,访问相机需要设置相关的权限 麦克风权限:Privacy - Microphone Usage Description 是否允许此App使用你的麦克风? 相机权限: Priva ...

  5. 想入门webpack,这篇就够了

    申明:本文转载自简书 文/zhangwang(简书作者)原文链接:http://www.jianshu.com/p/42e11515c10f#著作权归作者所有,转载请联系作者获得授权,并标注" ...

  6. 面试题-Java Web-网络通信

    1.HTTP响应的结构是怎么样的? HTTP响应由三个部分组成:状态码(Status Code):描述了响应的状态.可以用来检查是否成功的完成了请求.请求失败的情况下,状态码可用来找出失败的原因.如果 ...

  7. Tiny6410之UART裸机驱动

    UART简介: UART(Universal Asynchronous Receiver and Transmitter)通用异步收发器(异步串行通信口),是一种通用的数据通信协议,它包括了RS232 ...

  8. openstack私有云布署实践【18 修改实例DHCP服务的DNS IP】

    某天,由于Linux服务器默认没有DNS缓存功能,每次服务器每访问一个http域名链接时,都会触发一次DNS域名解析查询,降低了调用API接口的时延,所以我司后续启用的内网的dnsmasq DNS服务 ...

  9. Java代理模式汇总

    简介 代理模式即Proxy Pattern,23种java常用设计模式之一.其定义为:对其他对象提供一种代理以控制对这个对象的访问. UML类图 静态代理 目标接口 public interface ...

  10. ubuntu16.04 禁用Guest用户

    .打开终端(快捷键 Ctrl+Alt+T) .编辑50-no-guest.conf文件,按照以下命令编辑, sudo gedit /usr/share/lightdm/lightdm.conf.d/- ...