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 ...
随机推荐
- Unity中内嵌网页插件UniWebView使用总结
目前有三种方式可以实现在Unity工程中实现内嵌网页的功能: 1. UnityWebCore:只支持Windows平台,调用浏览器内核,将网页渲染到mesh,作为gameObject. 2. Un ...
- @classmethod装饰器
当一个类中有多条用例,我们在执行的时候每执行一条用例就要重新打开一次浏览器操作,例如下: start test1 quit start test2 start 若我们使用@classmethod装饰器 ...
- ryu启动问题总结
在Mininet中启动ryu控制器,首先切换到ryu中的app目录下: cd ryu/ryu/app 启动ryu: ryu-manager simple_switch.py 遇到了如下的错误提示: 这 ...
- 理解PHP中会话控制
如果以前没有接触过建站或网络编程,只是从头开始学PHP,以及用PHP来建立动态站点,那么会话(SESSION)对于初学者就有点难理解.那么到底什么是会话呢?理解一个概念需要从它产生的背景或问题出发,所 ...
- 《挑战程序设计竞赛》2.2 贪心法-其它 POJ3617 3069 3253 2393 1017 3040 1862 3262
POJ3617 Best Cow Line 题意 给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下列任意操作: 从S的头部(或尾部)删除一个字符,加到T的尾部 ...
- JAVA 遍历文件夹下的所有文件(递归调用)
package file; import java.io.File; public class Test1 { public static void main(String[] args) { Str ...
- 6.javaScript中的二维数组
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- C++ 动态内存 栈堆
C++ 动态内存_w3cschool https://www.w3cschool.cn/cpp/cpp-dynamic-memory.html
- ini_set('date.timezone','Asia/Shanghai');
w 同样的代码,不一样的php ENV.
- lombok插件使用
1.1 lombok介绍 lombok 是一个可以帮助我们简化java代码编写的工具类,尤其是简化javabean的编写,可以通过采用注解的方式,消除代码中的构造方法,getter/setter等代码 ...