HDU 1503 Advanced Fruits(LCS+记录路径)
http://acm.hdu.edu.cn/showproblem.php?pid=1503
题意:
给出两个串,现在要确定一个尽量短的串,使得该串的子串包含了题目所给的两个串。
思路:
这道题目就是要我们求LCS,记录好路径就好。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = + ; char s1[maxn],s2[maxn];
int d[maxn][maxn];
int mark[maxn][maxn]; void LCS(int n, int m)
{
memset(d,,sizeof(d));
for(int i = ;i<=n;i++)
mark[i][] = ;
for(int i = ;i<=m;i++)
mark[][i] = ; for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(s1[i]==s2[j])
{
d[i][j]=d[i-][j-]+;
mark[i][j]=;
}
else
{
if(d[i-][j]>d[i][j-])
{
d[i][j]=d[i-][j];
mark[i][j]=;
}
else
{
d[i][j]=d[i][j-];
mark[i][j]=;
}
}
}
}
} void print(int i,int j)
{
if(i== && j==) return;
if(mark[i][j]==)
{
print(i-,j-);
printf("%c",s1[i]);
}
else if(mark[i][j]==)
{
print(i-,j);
printf("%c",s1[i]);
}
else
{
print(i,j-);
printf("%c",s2[j]);
}
} int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%s%s",s1+,s2+))
{
int len1=strlen(s1+);
int len2=strlen(s2+); LCS(len1,len2);
print(len1,len2);
printf("\n");
}
return ;
}
HDU 1503 Advanced Fruits(LCS+记录路径)的更多相关文章
- hdu 1503 Advanced Fruits(LCS输出路径)
Problem Description The company "21st Century Fruits" has specialized in creating new sort ...
- HDU 1503 Advanced Fruits (LCS,变形)
题意: 给两个水果名,要求他们的LCS部分只输出1次,其他照常输出,但是必须保持原来的顺序! 思路: 求LCS是常规的,但是输出麻烦了,要先求LCS,再标记两串中的所有LCS字符,在遇到LCS字符时, ...
- hdu 1503:Advanced Fruits(动态规划 DP & 最长公共子序列(LCS)问题升级版)
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1503 Advanced Fruits
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1503 思路:这是一道最长公共子序列的题目,当然还需要记录路径.把两个字符串的最长公共字串记录下来,在递 ...
- hdu 1503 Advanced Fruits(最长公共子序列)
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 最长公共子序列(加强版) Hdu 1503 Advanced Fruits
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1503 Advanced Fruits 最长公共子序列 *
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1503 Advanced Fruits(DP)
题意: 将两个英文单词进行合并.[最长公共子串只要保留一份] 输出合并后的英文单词. 思路: 求最长公共子串. 记录路径: mark[i][j]=-1:从mark[i-1][j]转移而来. mark[ ...
- 题解报告:hdu 1503 Advanced Fruits(LCS加强版)
Problem Description The company "21st Century Fruits" has specialized in creating new sort ...
随机推荐
- spfile与pfile
SYS@ora11g>show parameter spfile NAME TYPE------------------------------------ ------------------ ...
- JS实现拖拽效果
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...
- [Gradle] 发布构件到本地仓库
配置 需要发布构件的模块 build.gradle 加入如下配置 apply plugin: 'maven-publish' publishing { publications { mavenJava ...
- Django框架【基础篇】
Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...
- 如何打造高性能Web应用
Sean Hull是Heavyweight Internet Group的创始人兼高级顾问,拥有20年以上技术顾问相关经验,曾为多家知名机构提供咨询,其中包括The Hollywood Reporte ...
- RPN网络
Region Proposal Network RPN的实现方式:在conv5-3的卷积feature map上用一个n*n的sliding window(论文中n=3)生成一个长度为256(ZF网络 ...
- (1.4)DML增强功能-Output
Output在CRUD的区别 1.对于INSERT,可以引用inserted表以查询新行的属性.在insert into table output . 2.对于DELETE,可以引用deleted表以 ...
- Nginx 设置临时维护页面
Nginx 设置临时维护页面 http://www.myexception.cn/open-source/1753957.html http://blog.justwd.net/snippets/ng ...
- Windows 10 升级软件 Windows 10 易升
进入 https://www.microsoft.com/zh-cn/software-download/windows10 点立即更新,弹出如下下载地址. https://download.micr ...
- java模拟网页http-url访问
package com.iflytek; import java.io.InputStream; import java.net.HttpURLConnection; import java.net. ...