POJ1458 Common Subsequence
题目链接:http://poj.org/problem?id=1458
分析:最大公共子序列模板
1 #include<iostream>
2 #include<sstream>
3 #include<cstdio>
4 #include<cstdlib>
5 #include<string>
6 #include<cstring>
7 #include<algorithm>
8 #include<functional>
9 #include<iomanip>
10 #include<numeric>
11 #include<cmath>
12 #include<queue>
13 #include<vector>
14 #include<set>
15 #include<cctype>
16 const double PI = acos(-1.0);
17 const int INF = 0x3f3f3f3f;
18 const int NINF = -INF - 1;
19 const int maxn = 1e3 + 5;
20 typedef long long ll;
21 #define MOD 1000000007
22 using namespace std;
23 char a[maxn], b[maxn];
24 int dp[maxn][maxn];
25 int main()
26 {
27 while (scanf("%s", &a) != EOF)
28 {
29 scanf("%s", &b);
30 memset(dp, 0, sizeof(dp));
31 int len1 = strlen(a);
32 int len2 = strlen(b);
33 for (int i = 1; i <= len1; ++i)
34 {
35 for (int j = 1; j <= len2; ++j)
36 {
37 if (a[i - 1] == b[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
38 else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
39 }
40 }
41 printf("%d\n", dp[len1][len2]);
42 }
43 return 0;
44 }
POJ1458 Common Subsequence的更多相关文章
- POJ1458 Common Subsequence 【最长公共子序列】
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37614 Accepted: 15 ...
- POJ-1458 Common Subsequence(线性动规,最长公共子序列问题)
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44464 Accepted: 18186 ...
- POJ1458 Common Subsequence —— DP 最长公共子序列(LCS)
题目链接:http://poj.org/problem?id=1458 Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Tot ...
- poj1458 Common Subsequence ——最长公共子序列
link:http://poj.org/problem?id=1458 最基础的那种 #include <iostream> #include <cstdio> #includ ...
- POJ 1458 Common Subsequence(最长公共子序列LCS)
POJ1458 Common Subsequence(最长公共子序列LCS) http://poj.org/problem?id=1458 题意: 给你两个字符串, 要你求出两个字符串的最长公共子序列 ...
- HDU1159 && POJ1458:Common Subsequence(LCS)
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- 【POJ - 1458】Common Subsequence(动态规划)
Common Subsequence Descriptions: A subsequence of a given sequence is the given sequence with some e ...
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- LintCode Longest Common Subsequence
原题链接在这里:http://www.lintcode.com/en/problem/longest-common-subsequence/ 题目: Given two strings, find t ...
随机推荐
- zjnu1716 NEKAMELEONI (线段树)
Description "Hey! I have an awesome task with chameleons, 5 th task for Saturday's competition. ...
- Codeforces Round #691 (Div. 2) C. Row GCD (数学)
题意:给你两个数组\(a\)和\(b\),对于\(j=1,...,m\),找出\(a_1+b_j,...,a_n+b_j\)的\(gcd\). 题解:我们很容易的得出\(gcd\)的一个性质:\(gc ...
- codeforces578C. Weakness and Poorness
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #498 (Div. 3) E. Military Problem (DFS)
题意:建一颗以\(1\)为根结点的树,询问\(q\)次,每次询问一个结点,问该结点的第\(k\)个子结点,如果不存在则输出\(-1\). 题解:该题数据范围较大,需要采用dfs预处理的方法,我们从结点 ...
- WPF 主动触发依赖属性的 PropertyChanged
需求背景 需要显示 ViewModel 中的 Message/DpMessage,显示内容根据其某些属性来确定.代码结构抽象如下: // Model public class Message : IN ...
- dart类详细讲解
dart 是一个面向对象的语言;面向对象有 (1)继承 (2)封装 (3)多态 dart的所有东西都是对象,所有的对象都是继承与object类 一个类通常是由属性和方法组成的哈: 在dart中如果你要 ...
- LINUX - vim高效操作
(一)可以为操作的一行添加下划线 set cursorline
- 字节笔试题 leetcode 69. x 的平方根
更多精彩文章请关注公众号:TanLiuYi00 题目 解题思路 题目要求非负整数 x 的平方根,相当于求函数 y = √x 中 y 的值. 函数 y = √x 图像如下: 从上图中,可以看出函数是单 ...
- Spring(二) Mini版Spring的实现
实现思路 先来介绍一下 Mini 版本的 Spring 基本实现思路,如下图所示: 自定义配置 配置 application.properties 文件 为了解析方便,我们用 application. ...
- Tomcat基本原理
思考 :怎样让Tomcat具备Web服务的功能呢? 在服务端用HTTP来监听,协议不好写,不妨用Java封装好的Socket作为监听. class MyTomcat{ ServerSocket ser ...