POJ1458 Common Subsequence —— DP 最长公共子序列(LCS)
题目链接:http://poj.org/problem?id=1458
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 55099 | Accepted: 22973 |
Description
Input
Output
Sample Input
abcfbc abfcab
programming contest
abcd mnp
Sample Output
4
2
0
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e3+; char a[MAXN], b[MAXN];
int dp[MAXN][MAXN]; int main()
{
while(scanf("%s%s", a+, b+)!=EOF)
{
int n = strlen(a+);
int m = strlen(b+); ms(dp, );
for(int i = ; i<=n; i++)
for(int j = ; j<=m; j++)
{
if(a[i]==b[j])
dp[i][j] = dp[i-][j-]+;
else
dp[i][j] = max(dp[i][j-], dp[i-][j]);
}
printf("%d\n", dp[n][m]);
}
}
POJ1458 Common Subsequence —— DP 最长公共子序列(LCS)的更多相关文章
- 题解报告:hdu 1159 Common Subsequence(最长公共子序列LCS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Problem Description 给定序列的子序列是给定的序列,其中有一些元素(可能没有) ...
- POJ - 1458 Common Subsequence DP最长公共子序列(LCS)
Common Subsequence A subsequence of a given sequence is the given sequence with some elements (possi ...
- POJ1458 Common Subsequence 【最长公共子序列】
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37614 Accepted: 15 ...
- hdu 1159 Common Subsequence(最长公共子序列,DP)
题意: 两个字符串,判断最长公共子序列的长度. 思路: 直接看代码,,注意边界处理 代码: char s1[505], s2[505]; int dp[505][505]; int main(){ w ...
- hdu 1159 Common Subsequence (最长公共子序列 +代码)
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- POJ 1458 Common Subsequence 【最长公共子序列】
解题思路:先注意到序列和串的区别,序列不需要连续,而串是需要连续的,先由样例abcfbc abfcab画一个表格分析,用dp[i][j]储存当比较到s1[i],s2[j]时最长公共子序 ...
- POJ 1458 Common Subsequence(最长公共子序列)
题目链接Time Limit: 1000MS Memory Limit: 10000K Total Submissions: Accepted: Description A subsequence o ...
- hdu 1159 Common Subsequence(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- HDU 1159 Common Subsequence 【最长公共子序列】模板题
题目链接:https://vjudge.net/contest/124428#problem/A 题目大意:给出两个字符串,求其最长公共子序列的长度. 最长公共子序列算法详解:https://blog ...
随机推荐
- [SHELL]awk的用法举例
从初学awk到现在小有所成,非常感谢CUers的帮助,总结了下自己曾经遇到的问题和犯的错误,供初学者借鉴,因本人非计算机专业,对专业词汇可能有表述不对的地方,还请指正和补充! 1. awk '{cod ...
- Java学习之正则表达式
Java正则表达式字符串模式. 正则表达式可以用来搜索.编辑和处理文本. 正则表达式不尽限于一种语言,但在每一种语言中又细微的差别. java.util.regex包中主要有这3个类: Pattern ...
- 使现有的VSCode成为便携版(绿色版)
VSCode可以说是各种代码编辑器前端之中的神器了,相对体积小且扩展性强,我们希望将它携带在U盘中在各种工作环境中使用,官方也提供了在Windows,Linux和MacOS三大平台中使VSCode便携 ...
- windows 配置 apache的多个站点
windows 配置apache的多个站点 第一步打开apache的conf/extra/httpd-vhosts.conf,复制<VirtualHost></VirtualHost ...
- poj1459多源多汇最大流问题
/*基本构图题,多源多汇,添加一个源点和一个汇点,所有源点都来自这个源点,同理,所有汇点 都汇于这个汇点,dinic第二战,本来应该1A的,犯了一个低级错误!while(scanf("%d) ...
- Spring Cloud(8):Sleuth和Zipkin的使用
场景: 某大型电商网站基于微服务架构,服务模块有几十个. 某天,测试人员报告该网站响应速度过慢.排除了网络问题之后,发现很难进一步去排除故障. 那么:如何对微服务的链路进行监控呢? Sleuth: 一 ...
- Linux后台运行命令nohub输出pid到文件(转)
用nohup可以启动一个后台进程.让一个占用前台的程序在后台运行,并静默输出日志到文件: nohup command > logfile.txt & 但是如果需要结束这个进程,一般做法是 ...
- Spring Boot使用MyBatis 3打印SQL的配置
普通Spring下的XML文件配置: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE co ...
- 关于MSSQL的decimal(numeric)、money、float的使用以及区别
decimal(numeric).money.float(real) 都是MSSQL中的浮点类型的数据类型. 按存储的范围进行排序 float(real) decimal(numeric) money ...
- Java处理XSS漏洞的工具类代码
原文:http://www.open-open.com/code/view/1455809388308 public class AntiXSS { /** * 滤除content中的危险 HTML ...