最长公共子序列。状态转移方程见代码。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char s1[1005],s2[1005];
int dp[1005][1005];
int main()
{
while(scanf("%s",s1+1)!=EOF)
{
scanf("%s",s2+1);
memset(dp,0,sizeof(dp));
int len1=strlen(s1+1);
int len2=strlen(s2+1);
for(int i=1;i<=len1;i++)
for(int j=1;j<=len2;j++)
{
if(s1[i]==s2[j])
{
dp[i][j]=dp[i-1][j-1]+1;
}
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
printf("%d\n",dp[len1][len2]);
}
return 0;
}

HDU 1159 &amp;&amp; POJ 1458的更多相关文章

  1. HDU 1159 Common Subsequence(POJ 1458)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...

  2. LCS POJ 1458 Common Subsequence

    题目传送门 题意:输出两字符串的最长公共子序列长度 分析:LCS(Longest Common Subsequence)裸题.状态转移方程:dp[i+1][j+1] = dp[i][j] + 1; ( ...

  3. HDU 1159 Common Subsequence

    HDU 1159 题目大意:给定两个字符串,求他们的最长公共子序列的长度 解题思路:设字符串 a = "a0,a1,a2,a3...am-1"(长度为m), b = "b ...

  4. hdu 1159 Palindrome(回文串) 动态规划

    题意:输入一个字符串,至少插入几个字符可以变成回文串(左右对称的字符串) 分析:f[x][y]代表x与y个字符间至少插入f[x][y]个字符可以变成回文串,可以利用动态规划的思想,求解 状态转化方程: ...

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

    POJ 1458 Common Subsequence(LCS最长公共子序列)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

  6. POJ 1458 最长公共子序列(dp)

    POJ 1458 最长公共子序列 题目大意:给出两个字符串,求出这样的一 个最长的公共子序列的长度:子序列 中的每个字符都能在两个原串中找到, 而且每个字符的先后顺序和原串中的 先后顺序一致. Sam ...

  7. HDU 1159 Common Subsequence 最长公共子序列

    HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...

  8. POJ 1458 Common Subsequence (动态规划)

    题目传送门 POJ 1458 Description A subsequence of a given sequence is the given sequence with some element ...

  9. POJ 1458 1159

    http://poj.org/problem?id=1458 一道容易的DP,求最长公共子序列的 dp[i][j],代表str1中的第i个字母和str2中的第j个字母的最多的公共字母数 #includ ...

随机推荐

  1. angular中使用AMEXIO

    1.用NPM添加依赖到项目中,amexio需要先添加以下四个依赖到项目 npm install jquery@3.2.1  --save npm install bootstrap@4.0.0-alp ...

  2. Lynx以纯文本的形式下载网页

    Lynx是一款基于命令行的web浏览器 [root@test88 ~]# yum install lynx -y [root@test88 ~]# lynx www.baidu.com 以纯文本的形式 ...

  3. C语言使用数学库编译不通过问题

    #include <stdio.h>#include <math.h> int main(){        double a = 10.0,b = 3.0;        f ...

  4. linux中使用vim编译C++程序

    Vi三种模式详解 命令行模式 (command mode/一般模式) 任何时候,不管用户处于何种模式,只要按一下“ESC”键,即可使Vi进入命令行模式:我们在shell环境(提示符为$)下输入启动Vi ...

  5. 洛谷P1634 禽兽的传染病 题解

    题目传送门 最近都在刷红色的水题... 这道题因为是不断地传染,所以直接求幂次方就好啦... 但是一测样例WA了... 原来x初始需要加1... 提交评测WA了... 原来要开long long .. ...

  6. lr的脚本调试方法

    1)  设置调试断点(快捷键F9)当设置断点的脚本,脚本运行到断点处,自动停止运行,我们可以通过查看运行日志,来观察脚本执行的情况: LR中也能设置断点,具体菜单在:Insert - Toggle B ...

  7. ubuntu sublime text 3 build 3083 license

    经验证:sublime text 3 3083可用 ----- BEGIN LICENSE -----Andrew WeberSingle User LicenseEA7E-855605813A03D ...

  8. Check whether a + b = c or not after removing all zeroes from a,b and c

    Check whether a + b = c or not after removing all zeroes from a,b and c Given two integers a and b, ...

  9. shell-命令行参数(转)

    命令行参数 (转自http://c.biancheng.net/cpp/view/2739.html) 特殊变量列表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n 是一个数字, ...

  10. 图形管线之旅 Part2

    原文:<A trip through the Graphics Pipeline 2011> 翻译:往昔之剑   转载请注明出处   还没那么快   在上一篇,讲述了渲染命令在被GPU处理 ...