/*
给两个串a,b。输出一个最短的串(含等于a的子序列且含等于b的子序列)
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int maxn=;
int dp[maxn][maxn],path[maxn][maxn];
int len,len1,len2;
char text[maxn],a[maxn],b[maxn]; void getpath()
{
int n=len,i=len1,j=len2;
while(n)
{
if(path[i][j]==)
text[n--]=a[i],i--,j--;
else if(path[i][j]==) i--;
else j--;
}
} int main()
{
int i,j,k;
a[]=b[]='';
while(~scanf("%s%s",a+,b+))
{
memset(dp,,sizeof(dp));
len1=strlen(a)-,len2=strlen(b)-;
for(i=;i<=len1;i++)
{
for(j=;j<=len2;j++)
{
if(a[i]==b[j])dp[i][j]=dp[i-][j-]+,path[i][j]=;
else
{
if(dp[i-][j]>dp[i][j-]) dp[i][j]=dp[i-][j],path[i][j]=;
else dp[i][j]=dp[i][j-],path[i][j]=;
}
}
}
len=dp[len1][len2];
getpath();
j=,k=;
for(i=;i<=len;i++)
{
while(a[j]!=text[i]) printf("%c",a[j++]);
while(b[k]!=text[i]) printf("%c",b[k++]);
printf("%c",text[i]);
j++;k++;
}
while(j<=len1) printf("%c",a[j++]);
while(k<=len2) printf("%c",b[k++]);
printf("\n");
}
return ;
}

最新文章

  1. [Android]使用Dagger 2依赖注入 - API(翻译)
  2. [LeetCode] Rank Scores 分数排行
  3. Node.js学习之简介
  4. .net网站能走多远
  5. HTTP权威指南笔记-2.URL与资源
  6. Hbase写入hdfs源码分析
  7. json 特殊字符 javascript 特殊字符处理(转载)
  8. opencv的一次性配置
  9. jquery Ajax应用总结
  10. CSS动画:Transform中使用频繁的scale,rotate,translate动画
  11. 转:PHP 使用ZipArchive压缩文件并下载
  12. ProgressDialog(四)——更改系统自带ProgressDialog文字大小
  13. Git建空白分支
  14. &lt;c:forEach var=&quot;role&quot; items=&quot;[entity.Role@d54d4d, entity.Role@1c61868, entity.Role@6c58db, entity.Role@13da8a5]&quot;&gt; list 集合数据转换异常
  15. git 入门与应用
  16. Latex常用软件
  17. 四、Sql Server 基础培训《进度4-插入数据(实际操作)》
  18. Java基本语法---个人参考资料
  19. C#开发Unity游戏教程之使用脚本变量
  20. yum使用过程中的常见错误

热门文章

  1. 使用Vue CLI 3快速创建项目
  2. H5各种头部meta标签的功能
  3. float浮动布局(慕课网CSS笔记 + css核心技术详解第四章)
  4. python3 练习题100例 (十三)
  5. python3中文件的读与写
  6. usb gadge驱动设计之我是zero
  7. Linux系统软件包之---Apache
  8. 非常好用的CSS样式重置表
  9. TCP/IP网络编程之基于TCP的服务端/客户端(一)
  10. RemoteFX