HDU1159 && POJ1458:Common Subsequence(LCS)
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
题意:求出两个串的公共子序列的长度
思路:LCS的入门题,直接模板就可以了
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; char s1[1000],s2[1000];
int dp[1000][1000];
int len1,len2; void LCS()
{
int i,j;
memset(dp,0,sizeof(dp));
for(i = 1; i<=len1; i++)
{
for(j = 1; j<=len2; j++)
{
if(s1[i-1] == s2[j-1])
dp[i][j] = dp[i-1][j-1]+1;
else
dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
}
}
} int main()
{
while(~scanf("%s%s",s1,s2))
{
len1 = strlen(s1);
len2 = strlen(s2);
LCS();
printf("%d\n",dp[len1][len2]);
} return 0;
}
HDU1159 && POJ1458:Common Subsequence(LCS)的更多相关文章
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- HDU 1159:Common Subsequence(LCS模板)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 【水:最长公共子序列】【HDU1159】【Common Subsequence】
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Common Subsequence LCS
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/F 题目: Description A subsequ ...
- Poj 1458 Common Subsequence(LCS)
一.Description A subsequence of a given sequence is the given sequence with some elements (possible n ...
- 算法:Common Subsequence(动态规划 Java 最长子序列)
Description A subsequence of a given sequence is the given sequence with some elements (possible non ...
- hdu 1159 Common Subsequence(LCS最长公共子序列)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 最长公共字串算法, 文本比较算法, longest common subsequence(LCS) algorithm
''' merge two configure files, basic file is aFile insert the added content of bFile compare to aFil ...
- POJ 1458:Common Subsequence
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 41957 Accepted: 16 ...
随机推荐
- UIImageView添加边框和阴影
- (void)viewDidLoad { [super viewDidLoad]; //添加显示 UIImage *image = [UIImage imageNamed:@"0_wang ...
- ubuntu远程连接
apt-cache search openssh-server //直接用apt-get install openssh-server安装.记不清包名字时可用apt-cache search o ...
- mybatis审查要点
1.where条件遗漏情况 <select id="findActiveBlogLike" resultType="Blog"> SELECT * ...
- js bind
1.作用 函数的bind方法用于将函数体内的this绑定到某个对象,然后返回一个新函数. //bind 相比于call apply this 都等于 obj; bind是产生一个新的函数 不执 ...
- iOS开发,新手入门指导
在做了近两年wp,安卓开发之后,某一天突然决定投身iOS的开发之中. 因为一直用的mac,做wp开发的时候都用双系统,vs开久了,就会比较烫,这点让人不爽.后来更多地做安卓,直接mac下开发,很舒适的 ...
- phpcms首页商机的调用,多种方式
<hr /> {pc:get sql="select * from phpcms_yp_buy" order="updatetime DESC"} ...
- · HTML使用Viewport
· HTML使用ViewportViewport可以加速页面的渲染,请使用以下代码<meta name=”viewport” content=”width=device-width, initi ...
- Dapper中使用存储分页。
#region 分页获取数据 /// <summary> /// 分页获取数据 /// </summary> /// <typeparam name="T&qu ...
- totolink的n200r路由在卓越网和京东网的价钱
totolink的n200r路由在卓越网和京东网的价钱, 应朋友需要帮忙买totolink的n200r的路由, 一向是在京东买电子产品的,之前都有在卓越网购物,所以今天也去看看卓越网上n200r的价格 ...
- FLASK初步实践
感觉经过DJANGO,CI,RAILS之类的WEB框架之后,FLASK的思路就比较顺畅了... FLASKR.PY import sqlite3 from flask import Flask, re ...