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 ...
随机推荐
- 【uva 10048】Audiophobia(图论--Floyd算法)
题意:有一个N点M边的无向带权图,边权表示路径上的噪声值.有Q个询问,输出 x,y 两点间的最大噪声值最小的路径的该值.(N≤100,M≤1000,Q≤10000) 解法:N值小,且问多对点之间的路径 ...
- POJ1142 Smith Numbers 暴力+分解质因子
题意:题目定义了一个史密斯数,这个数的定义是:一个合数的各个位置上加起来的和等于它的素因数所有位置上的数字加起来的和.比如: 4937775=3∗5∗5∗658374+9+3+7+7+7+5=3+5+ ...
- Long Long Message POJ - 2774 后缀数组
The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him ...
- JavaScript函数console、this关键字
console.dir()打印出来的东西不加任何操作 console.log()打印出来东西实现进行了操作,打印出来的东西可能不是原型 具体对象的类型可以在"_proto_"中看, ...
- KVM Pass-through 上部署 MiniSMB HurricaneII
KVM Pass-through 上部署 MiniSMB HurricaneII 免费网络测试,是一款专门用于测试无线控制器, 智能路由器,网络交换机的性能和稳定性的软硬件相结合的工具.可以通过此工具 ...
- Linux-文件查看命令
目录 系统文件查看命令-cat 系统文件查看命令-more 系统文件查看命令-less 系统文件查看命令-head 系统文件查看命令-tail 系统文件查看命令-grep 文件上传下载命令-rz,sz ...
- ArcGIS处理栅格数据(一)
一.建立影像金字塔 ArcToolbox--数据管理工具--栅格--栅格属性--构建金字塔(pyramid) 说明:该方式一次只能为一张影像数据建立影像金字塔. ArcToolbox--数据管理工具- ...
- 流水线cpu —Verilog HDL
一.准备工作 先看看书(<计算机原理与设计 Verilog HDL版>),搞懂一点原理.然后照着书上的代码写一写(用8.4的就可以了,不用8.6的). 注意mux2x32,mux4,cla ...
- mssql数据库提权(xp_cmdshell)
1.关于 "xp_cmdshell" "存储过程":其实质就是一个"集合",那么是什么样的结合呢,就是存储在SqlServer中预先定义好的 ...
- 吐槽 Apple iPhone 十大反人类的设计 All In One
吐槽 Apple iPhone 十大反人类的设计 All In One 不支持 GPS 快捷开关 每次都要到,设置> 隐身 > 位置,脑残的设计 顶部的状态栏,网络不支持显示网速 顶部的状 ...