#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. div和span元素的区别

    2个都是用来划分区间但是没有实际语义的标签,差别就在于div是块级元素,不会其他元素在同一行;span是内联元素,可以与其他元素位于同一行. DIV 和 SPAN 元素最大的特点是默认都没有对元素内的 ...

  2. Devexpress VCL Build v2013 vol 13.2.5 发布

    支持xe6 了,但是承诺的功能在哪里? What's New in 13.2.5 (VCL Product Line)   New Major Features in 13.2 What's New ...

  3. kbmMWEncodeEscapes 中汉字编码的问题及解决办法

    kbmMWEncodeEscapes 是kbmmw 里面的一个函数,用来对URL 中的汉字进行编码,例如 http://127.0.0.1/getname?name=春节,由于'春节'是汉字,浏览器向 ...

  4. htoi的实现

    htoi的实现 /************************************************************************* > File Name: h ...

  5. C++之类和对象课后习题1

    建立一个对象数组,内放5个学生的(学号,成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生的最高成绩者,并输出其学号. #include<iostream> ...

  6. UVa 11039 Building designing (贪心+排序+模拟)

    题意:给定n个非0绝对值不相同的数,让他们排成一列,符号交替但绝对值递增,求最长的序列长度. 析:我个去简单啊,也就是个水题.首先先把他们的绝对值按递增的顺序排序,然后呢,挨着扫一遍,只有符号不同才计 ...

  7. MemCachedClient 节点失效时的处理

    引入jar包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3 ...

  8. MFC框架仿真<二>

  9. Spark应用程序的运行架构几种说

    (1)简单的说: 由driver向集群申请资源,集群分配资源,启动executor.driver将spark应用程序的代码和文件传送给executor.executor上运行task,运行完之后将结果 ...

  10. ACL登陆认证

    前篇文章ACL授权实例介绍了授权,授权完成之后,就要进行认证.ACL的认证主要分为登陆认证与即时认证.所谓登录认证就是在用户登陆的时候,进行信息认证.根据用户Id,加载上来该用户所拥有的权限模块:而即 ...