poj2250
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
char a[][],b[][];
int dir[][],dp[][];
int LCS(int n,int m)
{
int i,j;
for(i=;i<=n;i++)//为了方便从1开始但是下面的i-1对正下标
for(j=;j<=m;j++)
{
if(strcmp(a[i-],b[j-])==)
{
dp[i][j]=dp[i-][j-]+;
dir[i][j]=;
}
else if(dp[i-][j]>=dp[i][j-])
{
dp[i][j]=dp[i-][j];
dir[i][j]=;
}
else
{
dp[i][j]=dp[i][j-];
dir[i][j]=;
}
}
return dp[n][m];
}
void print(int r,int c)
{
if(r== || c==) return;
if(dir[r][c]==)
{
print(r-,c-);
printf("%s ",a[r-]);
}
else if(dir[r][c]==) print(r-,c);
else print(r,c-);
}
int main()
{
int i,n,m;
char s[];
while(scanf("%s",&s)!=EOF)
{
n=;
int flag=;
strcpy(a[n++],s);
while(flag)
{
scanf("%s",a[n++]);
if(a[n-][]=='#') flag=;
}
/*for(i=0;i<n;i++)
printf("%s\n",a[i]);*/
n=n-;
flag=;
m=;
while(flag)
{
scanf("%s",b[m++]);
if(b[m-][]=='#') flag=;
}
/*for(i=0;i<m;i++)
printf("%s\n",b[i]);*/
m=m-;
//printf("%d\n",LCS(n,m));
LCS(n,m);
print(n,m);
//printf("\n");
}
return ;
}
18:09:13
poj2250的更多相关文章
- poj2250 最长上升子序列 + 输出
//Accepted 208 KB 0 ms //最长公共上升子序列+输出 //dp //输出时用的递归输出,注意条件判断 #include <cstdio> #include <c ...
- POJ2250 - Compromise(LCS+打印路径)
题目大意 给定两段文本,问公共单词有多少个 题解 裸LCS... 代码: #include<iostream> #include<string> using namespace ...
- POJ2250:Compromise(LCS)
Description In a few months the European Currency Union will become a reality. However, to join the ...
- 最长公共单词,类似LCS,(POJ2250)
题目链接:http://poj.org/problem?id=2250 解题报告: 1.状态转移方程: ; i<=len1; i++) { ; j<=len2; j++) { dp[i][ ...
- DP总结 ——QPH
常见优化 单调队列 形式 dp[i]=min{f(k)} dp[i]=max{f(k)} 要求 f(k)是关于k的函数 k的范围和i有关 转移方法 维护一个单调递增(减)的队列,可以在两头弹出元素,一 ...
- POJ 2250 Compromise【LCS】+输出路径
题目链接:https://vjudge.net/problem/POJ-2250 题目大意:给出n组case,每组case由两部分组成,分别包含若干个单词,都以“#”当结束标志,要求输出最长子序列. ...
- 动态规划_线性dp
https://www.cnblogs.com/31415926535x/p/10415694.html 线性dp是很基础的一种动态规划,,经典题和他的变种有很多,比如两个串的LCS,LIS,最大子序 ...
- dp之最长递增、公共子序列总结
1.最长递增子序列模板poj2533(时间复杂度O(n*n)) #include<iostream> #include<stdio.h> #include<string. ...
- poj分类解题报告索引
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...
随机推荐
- wordpress简单搭建个人博客
一.环境要求 centos6.5 x64mysql5.6.19php5.5lighttpd1.4.28 二.安装步骤 install mysql5.6.19 from source:0. prepar ...
- asp.net页面触发事件panel滚动条高度不变的实现方法
asp.net页面按钮点击触发事件后panel滚动条非自动回到顶端,每次都要往下拉一下,关于这个问题的解决方法如下 此文是为解决asp.net页面按钮点击触发事件后panel滚动条非自动回到顶端的解决 ...
- map实现
/*PLSQL实现Map*/ --建立序列create sequence seq_map_param_id ;--建立参数表create table map_param(id number prima ...
- Android无线测试之—UiAutomator UiObject API介绍六
手势操作 1.手势相关操作 2.相关API介绍 返回值 API 描述 boolean performMultiPointerGesture(PointerCoords[]... touches) 执行 ...
- std::stringstream(2)
stringstream本身的复制构造函数是私有的,无法直接用,于是带来了一些复杂的问题 网上,流传着几种办法,如streamA.str(streamB.str()),但这种办法,复制的仅仅是初始化时 ...
- mvc jsonresult 前台、后台解析
背景介绍:asp.net中使用json对象传参;mvc中可以直接使用jsonresult这个对象 一:怎么使用jsonresult public JsonResult text() { var str ...
- HDU 3578 Greedy Tino(双塔DP)
Greedy Tino Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- <td></td>之间的
今天开发中遇到了一个很丢脸的事:我把下图中别人写的 给去掉了,我觉得这个很多余,结果被在大神们痛斥了一顿.因为去掉这个 会导致td之间没有数据时td的边框不显示的问题,所以几下这个惨痛的教训,以自警. ...
- delphi --批量添加
公共批量添加方法 function BatchSQL(DC : TADOConnection; Qry : TADOQuery; StrSQL : TStrings): Boolean; var i ...
- 01Go开发环境搭建(参考无闻大神)
一直安装下一步就可以了 GOPATH是工作目录 GOROOT是安装目录 如果有多个工作目录,就需要我们用分号进行分隔