HDU 1159 Common Subsequence(dp LCS)

Problem Description A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = another sequence Z = is a subsequence of X if there exists a strictly increasing sequence of indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = is a subsequence of X = with index sequence . 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.

Sample Input

abcfbc abfcab programming contest abcd mnp

Sample Output

4 2 0

Source Southeastern Europe 2003


#include #include #include using namespace std; int max(int a,int b) { return a>b? a:b; } char a[1001],b[1001]; int dp[1000][1000]; int main() { while(scanf("%s%s",a,b)!=EOF) { int lena=strlen(a); int lenb=strlen(b); int i; for(i=0;i

点击复制链接 与好友分享!回本站首页
上一篇:基于单个 div 的 CSS 绘图

NOJ[1093] HTML 即HDU1088 对字符串


HDU 1159 Common Subsequence(dp LCS)
CSS3实战开发: 纯CS

分类:默认分类 时间:2015-03-03 人气:8


Copyright (C) quwantang.com, All Rights Reserved.

趣玩堂 版权所有 京ICP备15002868号

processed in 0.043 (s). 10 q(s)