hdu1503
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<iomanip>
#define INF 99999999
using namespace std; const int MAX=100+10;
char a[MAX],b[MAX];
int dp[MAX][MAX],per[MAX][MAX]; void Printf(int i,int j){
if(i+j == 0)return;
if(per[i][j] == 1)Printf(i-1,j),printf("%c",a[i]);
else if(per[i][j] == 2)Printf(i-1,j-1),printf("%c",a[i]);
else Printf(i,j-1),printf("%c",b[j]);
} int main(){
while(cin>>a+1>>b+1){
int maxl=0,la=strlen(a+1),lb=strlen(b+1);
memset(dp,0,sizeof dp);
memset(per,0,sizeof per);
for(int i=1;i<=la;++i)per[i][0]=1;
for(int i=1;i<=lb;++i)per[0][i]=3;
for(int i=1;a[i] != '\0';++i){
for(int j=1;b[j] != '\0';++j){
if(a[i] == b[j])dp[i][j]=dp[i-1][j-1]+1,per[i][j]=2;
else if(dp[i-1][j]>dp[i][j-1])dp[i][j]=dp[i-1][j],per[i][j]=1;
else dp[i][j]=dp[i][j-1],per[i][j]=3;
}
}
Printf(la,lb);
printf("\n");
}
return 0;
}
hdu1503的更多相关文章
- hdu1503 最长公共子序列变形
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...
- hdu1503(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1503 题意:由两个字符串构造出另一个字符串,该字符串包含前两个字符串(按字符顺序,但不一定连续),使该 ...
- HDU1503:Advanced Fruits(LCS)
Problem Description The company "21st Century Fruits" has specialized in creating new sort ...
- 最长公共子序列hdu1503
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1503 题意:给你两个字符串,把这两个字符串合并,使合并之后的字符串最短,并且合并之后的字符之间的相对位 ...
- HDU1503(LCS,记录路径)
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu1503 LCS
题意:如果有相同的字母,这些字母只输出一次.其余的都输出. 先做一次LCS,标记相同的字母,然后回溯输出. #include<stdio.h> #include<string.h&g ...
- 动态规划_线性dp
https://www.cnblogs.com/31415926535x/p/10415694.html 线性dp是很基础的一种动态规划,,经典题和他的变种有很多,比如两个串的LCS,LIS,最大子序 ...
随机推荐
- sortable.js 华丽丽的排序
首先导入这几个资源 <link href="/css/jquery-ui-1.10.3.custom.css" rel="stylesheet" type ...
- eclipse svn2.0.0插件 手动安装方法
org.tigris.subversion.javahl.ClientException: Unsupported working copy formatsvn: This client is too ...
- c/c++内存分配方式(转)
原文链接:http://blog.csdn.net/jing0611/article/details/4030237 1.内存分配方式 内存分配方式有三种: [1]从静态存储区域分配.内存在 程序编译 ...
- Keil4 每次选build 编译(F7)都全部编译的解决办法
Keil4 每次选build 编译(F7)都全部编译的解决办法 http://blog.csdn.net/wchengshen/article/details/50440079 Keil4 每次选bu ...
- 怎样使用windows命令行,用notepad打开某文件夹下面的所有文件
http://zhidao.baidu.com/question/2138815012359999388.html __________________________________________ ...
- oracle_SQL中ROWID与ROWNUM的使用(转)
转自:http://www.360doc.com/content/12/0802/11/219024_227802569.shtml rownum: ROWNUM是对结果集加的一个伪列, 即先查到结果 ...
- spring-mvc关键点掌握 high level
在本例中,我们将使用Spring MVC框架构建一个入门级web应用程序.Spring MVC 是Spring框架最重要的的模块之一.它以强大的Spring IoC容器为基础,并充分利用容器的特性来简 ...
- Best Component for Bitmap Image
The best is to purchase ImageEn and use the latest version. Coz nothing compares to ImageEn.... But ...
- Deflater与Inflater的压缩与解压缩
原文:Deflater与Inflater的压缩与解压缩 package util; import java.util.Arrays; import java.util.zip.Deflater; im ...
- 基于visual Studio2013解决C语言竞赛题之0522和为素
题目