#include <iostream>
#include <stack>
#define MAXN 150
#include <string> using namespace std; int dp[MAXN][MAXN];
int mark[MAXN][MAXN];
string s_1[MAXN];
string s_2[MAXN];
stack <string> coll; int main()
{
int i;
int j;
string tem;
int n_1;
int n_2;
//freopen("acm.acm","r",stdin);
while(cin>>tem)
{
s_1[] = tem;
i = ;
while(cin>>tem)
{
if(tem == "#")
{
break;
}
s_1[i ++] = tem;
}
n_1 = i;
i = ;
while(cin>>tem)
{
if(tem == "#")
{
break;
}
s_2[i ++] = tem;
}
n_2 = i;
dp[][] = ;
for(i = ; i <= n_1; ++ i)
{
dp[i][] = ;
}
for(i = ; i <= n_2; ++ i)
{
dp[][i] = ;
}
memset(mark,-,sizeof(mark));
for(i = ; i < n_1; ++ i)
{
for(j = ; j < n_2; ++ j)
{
if(s_1[i] == s_2[j])
{
dp[i+][j+] = dp[i][j] + ;
mark[i][j] = ; //相等来自i-1和j-1
}
else
{
if(dp[i+][j] > dp[i][j+])
{
dp[i+][j+] = dp[i+][j];
mark[i][j] = ; // j-1方向
}
else
{
dp[i+][j+] = dp[i][j+];
mark[i][j] = ; // i-1方向
}
}
}
} i = n_1-;
j = n_2-; while(mark[i][j] != - && j >= && i >= )
{
if(mark[i][j] == )
{
coll.push(s_1[i]);
-- i;
-- j;
}
else if(mark[i][j] == )
{
-- j;
}
else if(mark[i][j] == )
{
-- i;
}
} while(!coll.empty())
{
cout<<coll.top()<<" ";
coll.pop();
}
cout<<endl;
} }

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com

POJ 2250的更多相关文章

  1. POJ 2250 Compromise(LCS)

    POJ 2250 Compromise(LCS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#proble ...

  2. poj 2250 Compromise(区间dp)

    题目链接:http://poj.org/problem?id=2250 思路分析:最长公共子序列问题的变形,只是把字符变成了字符串,按照最长公共子序列的思路即可以求解. 代码如下: #include ...

  3. POJ 2250 (LCS,经典输出LCS序列 dfs)

    题目链接: http://poj.org/problem?id=2250 Compromise Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  4. 【POJ 2250】Compromise(最长公共子序列LCS)

    题目字符串的LCS,输出解我比较不会,dp的时候记录从哪里转移来的,之后要一步一步转移回去把解存起来然后输出. #include<cstdio> #include<cstring&g ...

  5. LCS(打印路径) POJ 2250 Compromise

    题目传送门 题意:求单词的最长公共子序列,并要求打印路径 分析:LCS 将单词看成一个点,dp[i][j] = dp[i-1][j-1] + 1 (s1[i] == s2[j]), dp[i][j] ...

  6. POJ 2250(LCS最长公共子序列)

    compromise Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u   Descri ...

  7. POJ 2250(最长公共子序列 变形)

    Description In a few months the European Currency Union will become a reality. However, to join the ...

  8. POJ 2250 Compromise (UVA 531)

    LCS问题.基金会DP. 我很伤心WA非常多.就在LCS问题,需要记录什么路. 反正自己的纪录path错误,最后,就容易上当. 没有优化,二维阵列,递归打印,cin.eof() 来识别 end of ...

  9. POJ 2250 Compromise【LCS】+输出路径

    题目链接:https://vjudge.net/problem/POJ-2250 题目大意:给出n组case,每组case由两部分组成,分别包含若干个单词,都以“#”当结束标志,要求输出最长子序列. ...

随机推荐

  1. linux CentOS 7 安装 RabbitMQ Erlang 21.0

    1. 安装erlang 安装依赖环境 yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixO ...

  2. Shell获取当前路径

    PRG="$0" while [ -h "$PRG" ]; do ls=`ls -ld "$PRG"` link=`expr "$ ...

  3. (二)spring-mvc-showcase 和 swagger-springmvc 的恩恩怨怨

    1. 搜索 spring showcase 就可以找到这篇 http://spring.io/blog/2010/07/22/spring-mvc-3-showcase 就是教你如何使用spring ...

  4. 基于NLP和GAN的小说影视化

    轮廓: https://tieba.baidu.com/p/1271120336 着色:

  5. 20155231 2016-2017-2 《Java程序设计》第9周学习总结

    20155231 2016-2017-2 <Java程序设计>第9周学习总结 教材学习内容总结 第十六章:整合数据库 Metadata即"诠读数据的数据",数据库是用来 ...

  6. java web 入门实例servlet篇(显示后台数据库列表,删除某一条记录并显示)

    编写过程中需要注意的问题: 1.建立eclipse动态web工程时,需要改写编译后class文件的位置,通常情况下是这个位置:/WebContent/WEB-INF/classes 2.配置的页面链接 ...

  7. 结对编程-四则运算生成器(java实现)

     结对伙伴:陈振华  项目要求 1.题目:实现一个自动生成小学四则运算题目的命令行程序. 2.需求: 1. 使用 -n 参数控制生成题目的个数 2. 使用 -r 参数控制题目中数值(自然数.真分数和真 ...

  8. [翻译] Using Custom Functions in a Report 在报表中使用自己义函数

    Using Custom Functions in a Report  在报表中使用自己义函数   FastReport has a large number of built-in standard ...

  9. [Openwrt 项目开发笔记]:PHP+Nginx安装(七)

    [Openwrt项目开发笔记]系列文章传送门:http://www.cnblogs.com/double-win/p/3888399.html 正文: 在上一节中,我们已经搭建了MySQL数据库了,因 ...

  10. Alwayson--使用证书创建高可用性组

    --场景: --有服务器SQLNode11,SQLNODE21,SQLNODE31三台在同一故障转移群集SQLNode01中 --的数据库服务器,安装SQL SERVER 2012 并配置启动alwa ...