【水:最长公共子序列】【HDU1159】【Common Subsequence】
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24919 Accepted Submission(s): 11035
..., ik> of indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = <a, b, f, c> is a subsequence of X = <a, b, c, f, b, c> with index sequence <1, 2, 4, 6>. Given two sequences X and Y the problem is to find the length of the maximum-length
common subsequence of X and Y.
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.
abcfbc abfcab
programming contest
abcd mnp
4
2
0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
using namespace std;
char A[1001],B[1001];
int F[1000][1000];
void solve()
{
memset(F,0,sizeof(F));
int lena=strlen(A);
int lenb=strlen(B);
F[0][0]=0;
F[0][1]=0;
F[1][0]=0;
for(int i=1;i<=lena;i++)
for(int j=1;j<=lenb;j++)
{
if(A[i-1]==B[j-1])
F[i][j]=F[i-1][j-1]+1;
else F[i][j]=max(F[i][j-1],F[i-1][j]);
}
printf("%d\n",F[lena][lenb]);
}
int main()
{
while(scanf("%s %s",A,B)!=EOF)
{
solve();
}
return 0;
}
【水:最长公共子序列】【HDU1159】【Common Subsequence】的更多相关文章
- 最长公共子序列(Longest common subsequence)
问题描述: 给定两个序列 X=<x1, x2, ..., xm>, Y<y1, y2, ..., yn>,求X和Y长度最长的公共子序列.(子序列中的字符不要求连续) 这道题可以 ...
- LCS最长公共子序列HDU1159
最近一直在学习算法,基本上都是在学习动态规划以及字符串.当然,两者交集最经典之一则是LCS问题. 首先LCS的问题基本上就是在字符串a,b之间找到最长的公共子序列,比如 YAOLONGBLOG 和 Y ...
- 最长公共子序列-Hdu1159
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 动态规划---最长公共子序列 hdu1159
hdu1159 题目要求两个字符串最长公共子序列, 状态转换方程 f[i][j]=f[i-1][j-1]+1; a[i]=b[j]时 f[i][j]=MAX{f[i-1][j],f[i][j-1] ...
- UVA10100:Longest Match(最长公共子序列)&&HDU1458Common Subsequence ( LCS)
题目链接:http://blog.csdn.net/u014361775/article/details/42873875 题目解析: 给定两行字符串序列,输出它们之间最大公共子单词的个数 对于给的两 ...
- 算法实践--最长公共子序列(Longest Common Subsquence)
什么是最长公共子序列 X=ACCG Y=CCAGCA 长度为1的公共子序列: {A} {C} {G} 长度为2的公共子序列:{AC} {CC} {CG} {AG} 长度为3的公共子序列:{ACG} 长 ...
- 算法练习——最长公共子序列的问题(LCS)
问题描述: 对于两个序列X和Y的公共子序列中,长度最长的那个,定义为X和Y的最长公共子序列.X Y 各自字符串有顺序,但是不一定需要相邻. 最长公共子串(Longest Common Subst ...
- [Python]最长公共子序列 VS 最长公共子串[动态规划]
前言 由于原微软开源的基于古老的perl语言的Rouge依赖环境实在难以搭建,遂跟着Rouge论文的描述自行实现. Rouge存在N.L.S.W.SU等几大子评估指标.在复现Rouge-L的函数时,便 ...
- 最长公共子串(Longest common substring)
问题描述: 给定两个序列 X=<x1, x2, ..., xm>, Y<y1, y2, ..., yn>,求X和Y长度最长的公共子串.(子串中的字符要求连续) 这道题和最长公共 ...
- Common Subsequence--poj1458(最长公共子序列)
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43211 Accepted: 17 ...
随机推荐
- 布局文件提示错误“No orientation specified, and the default is horizontal. This is a common so...”
完整的错误提示信息为:No orientation specified, and the default is horizontal. This is a common source of bugs ...
- Java核心技术,让计算机"一芯多用"的多线程技术
我们在使用计算的时候会感受到计算机好像在同时执行很多任务,这也是我最初接触计算机给我留下的印象,而我们普通人在同一时刻大脑只能思考一件事情(当然不排除一些异能者能够做到一心二用),而且我们在思考完一件 ...
- 用MVC4+EF改写XXX系统的计划--前言
感觉自己工作了三年,重来没有自己一个人写一个项目,从开始的策划,功能需求,业务逻辑,扩展,性能优化等等方面去做,从今天起准备发比半年时间重写XXX项目,每天中午和晚上分别花半个小时和一个小时开发,周末 ...
- 76 bytes for faster jQuery
转载自http://james.padolsey.com/javascript/76-bytes-for-faster-jquery/ 作者JAMES PADOLSEY 在我们平时使用JQuery,调 ...
- WebApi 文件上传
1. 注意给form表单加上enctype = "multipart/form-data" 属性,否则会导致Action的参数HttpPostedFileBase 对象接收不到文件 ...
- 生成html文件
第一步:建立一个MbPage.html页面 第二步:后台生成 public void ProcessRequest(HttpContext context) { c ...
- C#事件、委托简单示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 使用CSC.EXE编译第一个HELLO WORLD
坐的没事,下了个C#2008,看帮助文件写了个HELLO.CS的源文件: //hello.cs //Show "Hello Word!" using system; class h ...
- VB 基础语法以及教学视频
以下是我找到的几个视频和基础知识地址,我感觉比较不错的,现在分享给大家,你们都可以去借鉴以下 视频地址1:http://www.kcch.cn/excel2007_825.html 视频地址2:htt ...
- html5 canvas 一个漫天飞雪的效果
很棒的下雪效果 代码奉上 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...