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 ...
随机推荐
- H.264 Profile
提到High Profile H.264解码许多人并不了解,那么到底什么是High Profile H.264解码?其应用效果又是如何呢? 作为行业标准,H.264编码体系定义了4种不同的Profi ...
- wireshark in text mode: tshark
tshark -i <interface> -w "output.data" 抓到的数据可用wireshark打开查看.
- echarts使用要点
- CNN 各layer汇总
Flattening:类型为:Flatten 基于某个axis进行偏平的意思,如 axis = 1 ,fattens an input of shape n * c * h * w to a simp ...
- Docker入门与应用系列(五)Dockerfile
Dockerfile是为快速构建docker image而设计的,当你使用dockerbuild 命令的时候,docker 会读取当前目录下的命名为Dockerfile(首字母大写)的纯文本文件并执行 ...
- 【BZOJ4499】线性函数 线段树
[BZOJ4499]线性函数 Description 小C最近在学习线性函数,线性函数可以表示为:f(x) = kx + b.现在小C面前有n个线性函数fi(x)=kix+bi ,他对这n个线性函数执 ...
- 【BZOJ3813】奇数国 线段树+欧拉函数
[BZOJ3813]奇数国 Description 给定一个序列,每次改变一个位置的数,或是询问一段区间的数的乘积的phi值.每个数都可以表示成前60个质数的若干次方的乘积. Sample Input ...
- 搭建SVN和eclipse添加svn插件
在ubuntu服务器下安装svn服务器端,在window下使用eclipse的svn插件团队开发. 安装SVN服务端 1.在ubuntu上安装svn服务器 sudo apt-get install s ...
- List、Map、Set三个接口,存取元素时,各有什么特点?
List与Set都是单列元素的集合,它们有一个功共同的父接口Collection. Set里面不允许有重复的元素, 存元素:add方法有一个boolean的返回值,当集合中没有某个元素,此时add方法 ...
- Python生成器是什么
生成器是 Python 初级开发者最难理解的概念之一,虽被认为是 Python 编程中的高级技能,但在各种项目中可以随处见到生成器的身影,你得去理解它.使用它.甚至爱上它. 提到生成器,总不可避免地要 ...