hdu 1159 Common Subsequence(LCS最长公共子序列)
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18387 Accepted Submission(s): 7769
The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. For each set of data the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line.
programming contest
abcd mnp
2
0
题意:
s1的第i+1个字符位置要么匹配。要么不匹配。匹配的话只能和前j个位置匹配。
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int maxn=1010;
int dp[maxn][maxn];
char s1[maxn],s2[maxn];
int main()
{
int i,j,len1,len2; while(~scanf("%s%s",s1+1,s2+1))
{
len1=strlen(s1+1);
len2=strlen(s2+1);
memset(dp[0],0,sizeof dp[0]);
for(i=1;i<=len1;i++)
{
for(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 Common Subsequence(LCS最长公共子序列)的更多相关文章
- 题解报告:hdu 1159 Common Subsequence(最长公共子序列LCS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Problem Description 给定序列的子序列是给定的序列,其中有一些元素(可能没有) ...
- 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 (最长公共子序列 +代码)
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- HDU 1159 Common Subsequence 【最长公共子序列】模板题
题目链接:https://vjudge.net/contest/124428#problem/A 题目大意:给出两个字符串,求其最长公共子序列的长度. 最长公共子序列算法详解:https://blog ...
- hdu 1159 Common Subsequence(最长公共子序列,DP)
题意: 两个字符串,判断最长公共子序列的长度. 思路: 直接看代码,,注意边界处理 代码: char s1[505], s2[505]; int dp[505][505]; int main(){ w ...
- HDU - 1159 Common Subsequence (最长公共子序列)
A subsequence of a given sequence is the given sequence with some elements (possible none) left out. ...
- 杭电1159 Common Subsequence【最长公共子序列】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 解题思路:任意先给出两个字符串 abcfbc abfcab,用dp[i][j]来记录当前最长的子 ...
- HDU 1159 Common Subsequence (LCS)
题意:给定两行字符串,求最长公共子序列. 析:dp[i][j] 表示第一串以 i 个结尾和第二个串以 j 个结尾,最长公共子序列,剩下的就简单了. 代码如下: #pragma comment(link ...
- POJ 1458 Common Subsequence 【最长公共子序列】
解题思路:先注意到序列和串的区别,序列不需要连续,而串是需要连续的,先由样例abcfbc abfcab画一个表格分析,用dp[i][j]储存当比较到s1[i],s2[j]时最长公共子序 ...
随机推荐
- paip.索引优化---sql distict—order by 法
paip.索引优化---sql distict—order by 法 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog ...
- loadrunner java 缺少必要的导入包报错
loadrunner 运行从eclipse中做好的脚本,ctrl + A 复制到loadrunner中来, 添加参数化的的语句:verifyCode = lr.eval_string (&quo ...
- 数据库中的记录通过servlet回显到jsp页面中(连接数据库或者查询參照:对数据进行增删改查)
我们常常会用到通过图书的名称来查询图书那么这种话我们也就会使用到从数据库中搜索出数据而且载入到自己的Jsp页面中 这种话我们须要将从数据库中获取到的数据放进响应中然后通过%=request.getAt ...
- Makefile学习(二)条件判断和内嵌函数
第七章:Makefile的条件执行 条件语句可是是两个不同的变量.或者变量和常量值的比较: 7.1例子: 对变量“CC”进行判断,其值如果是“gcc ”那么在程序连接时使用库“libgnu.so”或者 ...
- unity提取打包资源
untiy打包资源是不可见的,在代码中须要www载入去提取,当然也有别的方法去提取打包资源.这对于非常久远的数据打包资源来说是个非常好的方法,由于太久远了就找不到了,仅仅能拿打包资源去提取,之前我写过 ...
- .Net的PDF转图片
用的是破解版的 O2S.Components.PDFRender4NET.dll 插件, 简单引用即可 public static class PdfToImage { , , ) { try { / ...
- Objective-C文件和目录操作,IOS文件操作,NSFileManager使用文件操作
http://blog.csdn.net/swingpyzf/article/details/15185767
- 0129——UINavigationController
1.创建一个UINavigationController self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].boun ...
- 2 读取solr下的索引文件(lucene文件)
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnaly ...
- Hadoop高可用平台搭建
文章概览: 1.机器规划和预配置 2.软件安装 3.集群文件配置 4.启动集群 5.HA验证 6.注意事项 7.小结 机器规划和预配置 主机/进程 NN DN RM NM ZK(QP) ZKFC ...