题目链接: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的更多相关文章

  1. POJ1458 Common Subsequence 【最长公共子序列】

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37614   Accepted: 15 ...

  2. POJ-1458 Common Subsequence(线性动规,最长公共子序列问题)

    Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44464 Accepted: 18186 ...

  3. POJ1458 Common Subsequence —— DP 最长公共子序列(LCS)

    题目链接:http://poj.org/problem?id=1458 Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  4. poj1458 Common Subsequence ——最长公共子序列

    link:http://poj.org/problem?id=1458 最基础的那种 #include <iostream> #include <cstdio> #includ ...

  5. POJ 1458 Common Subsequence(最长公共子序列LCS)

    POJ1458 Common Subsequence(最长公共子序列LCS) http://poj.org/problem?id=1458 题意: 给你两个字符串, 要你求出两个字符串的最长公共子序列 ...

  6. HDU1159 && POJ1458:Common Subsequence(LCS)

    Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...

  7. 【POJ - 1458】Common Subsequence(动态规划)

    Common Subsequence Descriptions: A subsequence of a given sequence is the given sequence with some e ...

  8. 动态规划求最长公共子序列(Longest Common Subsequence, LCS)

    1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...

  9. LintCode Longest Common Subsequence

    原题链接在这里:http://www.lintcode.com/en/problem/longest-common-subsequence/ 题目: Given two strings, find t ...

随机推荐

  1. bzoj3626: [LNOI2014]LCA (树链剖分+离线线段树)

    Description 给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1. 设dep[i]表示点i的深度,LCA(i,j)表示i与j的最近公共祖先. ...

  2. 【noi 2.6_9270】&【poj 2440】DNA(DP)

    题意:问长度为L的所有01串中,有多少个不包含"101"和"111"的串. 解法:f[i][j]表示长度为i的01串中,结尾2位的十进制数是j的合法串的个数.那 ...

  3. 9.PowerShell DSC之Pull

    前言 一般生产环境都使用Pull模式 配置Pull Server 配置Pull Server需要安装两个WindowsFeture:IIS.windows DSC,这两都可以通过UI界面化引导安装,也 ...

  4. kubernetes实战-配置中心(三)配置服务使用apollo配置中心

    使用配置中心,需要开发对代码进行调整,将一些配置,通过变量的形式配置到apollo中,服务通过配置中心来获取具体的配置 在配置中心修改新增如下配置: 项目信息: 配置: 重新打包镜像,使用apollo ...

  5. CDD All In One

    CDD All In One 组件驱动开发 (CDD) refs https://www.componentdriven.org/ https://www.learnstorybook.com/int ...

  6. element-ui UI 组件库剖析

    element-ui UI 组件库剖析 /* Automatically generated by './build/bin/build-entry.js' */ https://github.com ...

  7. Protocol Buffers All In One

    Protocol Buffers All In One Protocol Buffers - Google's data interchange format Protocol buffers are ...

  8. module patterns

    module patterns ebooks https://github.com/xyzata/2017-new-ebooks/blob/master/Succinctly/modulepatter ...

  9. git stash & git stash pop

    git stash & git stash pop $ git checkout feature/select-seat-system $ git checkout feature/app-d ...

  10. 关于TCP的Total Length

    TCP/IP传输层 文档 随便找了个发送的TCP: 70 89 cc ee 84 2c 3c 2c 30 a6 a2 d0 08 00 45 00 00 4c c7 a8 40 00 80 06 00 ...