博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Poj 1458 Common Subsequence(LCS)
阅读量:4312 次
发布时间:2019-06-06

本文共 1580 字,大约阅读时间需要 5 分钟。

Description

A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, ..., xm > another sequence Z = < z1, z2, ..., zk > is a subsequence of X if there exists a strictly increasing sequence < i1, i2, ..., ik > of indices of X such that for all j = 1,2,...,k, x 
ij = 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.

Input

The program input is from the std input. Each data set in the input contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct.

Output

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.

Sample Input

abcfbc         abfcabprogramming    contest abcd           mnp

Sample Output

420 题意:典型的求最长公共子序列。 ac代码:
1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 char s1[1000000],s2[1000000]; 7 int vis[500][500]; 8 int main() 9 {10 int i,j,n,m,n1,n2;11 while(scanf("%s",s1)!=EOF)12 {13 n1=0,n2=0;14 memset(vis,0,sizeof(vis));15 scanf("%s",s2);16 n1=strlen(s1);17 n2=strlen(s2);18 for(i=0; i

 

转载于:https://www.cnblogs.com/Xacm/p/3834088.html

你可能感兴趣的文章
网络虚拟化技术(二): TUN/TAP MACVLAN MACVTAP
查看>>
MQTT协议笔记之mqtt.io项目HTTP协议支持
查看>>
(转)jQuery中append(),prepend()与after(),before()的区别
查看>>
Tecplot: Legend和图像中 Dashed/Dash dot/Long dash 等虚线显示没有区别的问题
查看>>
win8 开发之旅(2) --连连看游戏开发 项目错误的总结
查看>>
视频转换工具ffmpeg
查看>>
一、 object c -基础学习第一天 如何定义一个类
查看>>
C#调用C++编译的DLL详解
查看>>
Kali Linux的安装
查看>>
我的大学生活-5-08-赵心宁
查看>>
黑马程序员-Java基础-反射
查看>>
bzoj1708[Usaco2007 Oct]Money奶牛的硬币(背包方案数dp)
查看>>
P2700逐个击破(并查集/树形dp)
查看>>
展望2018
查看>>
python几大排序算法
查看>>
hdu 4619 二分图最大匹配 ——最大独立集
查看>>
VM CentOS 问题汇总
查看>>
这段时间的小结
查看>>
ANDROID_MARS学习笔记_S01原始版_021_MP3PLAYER001_下载mp3文件
查看>>
第二周周六DailyReporting——PM(李忠)
查看>>