OpenJudge/Poj 1458 Common Subsequence
1.链接地址:
http://poj.org/problem?id=1458
http://bailian.openjudge.cn/practice/1458/
2.题目:
Common Subsequence
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35411 Accepted: 14080 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, 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.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 abfcab
programming contest
abcd mnpSample Output
4
2
0Source
3.思路:
4.代码:
#include "stdio.h"
//#include "stdlib.h"
#include "string.h"
#define N 1000
char a[N],b[N];
int c[N+][N+];
int dp(int lena,int lenb)
{
int i,j;
for(i=;i<=lena;i++) {c[i][]=;}
for(j=;j<=lenb;j++) {c[][j]=;}
for(i=;i<=lena;i++)
{
for(j=;j<=lenb;j++)
{
if(a[i-] == b[j-]) {c[i][j]=c[i-][j-]+;}
//if(i==1 && j==1){printf("%c %c\n",a[0],b[0]);}
else { c[i][j]=(c[i][j-]>c[i-][j])?c[i][j-]:c[i-][j]; }
//printf("%c %c %d\n",a[i-1],b[j-1],c[i][j]);
}
}
return c[lena][lenb];
}
int main()
{
int i,j;
while(scanf("%s%s",a,b) != EOF)
{
printf("%d\n",dp(strlen(a),strlen(b)));
//for(i=0;i<strlen(a);i++){for(j=0;j<strlen(b);j++){printf("%d ",c[i][j]);}printf("\n");}
}
//system("pause");
return ;
}
OpenJudge/Poj 1458 Common Subsequence的更多相关文章
- LCS POJ 1458 Common Subsequence
题目传送门 题意:输出两字符串的最长公共子序列长度 分析:LCS(Longest Common Subsequence)裸题.状态转移方程:dp[i+1][j+1] = dp[i][j] + 1; ( ...
- POJ 1458 Common Subsequence(LCS最长公共子序列)
POJ 1458 Common Subsequence(LCS最长公共子序列)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?c ...
- POJ 1458 Common Subsequence(最长公共子序列LCS)
POJ1458 Common Subsequence(最长公共子序列LCS) http://poj.org/problem?id=1458 题意: 给你两个字符串, 要你求出两个字符串的最长公共子序列 ...
- POJ 1458 Common Subsequence (动态规划)
题目传送门 POJ 1458 Description A subsequence of a given sequence is the given sequence with some element ...
- Poj 1458 Common Subsequence(LCS)
一.Description A subsequence of a given sequence is the given sequence with some elements (possible n ...
- poj 1458 Common Subsequence
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 46387 Accepted: 19 ...
- poj 1458 Common Subsequence【LCS】
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43132 Accepted: 17 ...
- (线性dp,LCS) POJ 1458 Common Subsequence
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65333 Accepted: 27 ...
- POJ - 1458 Common Subsequence DP最长公共子序列(LCS)
Common Subsequence A subsequence of a given sequence is the given sequence with some elements (possi ...
随机推荐
- 自己编写的基于VC++6.0的串口调试软件,并贡献源程序!
自己编写的基于VC++6.0的串口调试软件源程序! 程序下载链接: 点击打开链接
- winform 多线程中ShowDialog()步骤无效的解决办法
private void Form1_Load(object sender, EventArgs e) { Thread thread = new Thread(remind); thread.IsB ...
- 64位Ubuntu配置android环境报错(...adb": error=2, 没有那个文件或目录)
Failed to get the adb version: Cannot run program "/home/jayhomzhou/android/android-sdk/platfor ...
- dotnetfx35.exe
http://download.microsoft.com/download/2/0/e/20e90413-712f-438c-988e-fdaa79a8ac3d/dotnetfx35.exe
- ios 说一说UINavigationController 的堆栈
iOS的界面堆栈管理比android的要好用很多. 这里写两点:一点是 如何重回前面的vc,而不是push一个alloc的新界面.第二点就是判断当前堆栈显示的vc是何vc. vc堆栈: vc1-> ...
- ios基础知识
1获取系统语言设置 NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSArray *languages = ...
- ORA-12154 TNS无法解析指定的连接标识符
又是这个百无聊赖的问题,尽管问题芝麻点大,却让我们好找啊! 非常久没有安装oracle了.今天安装11g的时候,用PLSQL Developer连接时,就出现了这个俗不可耐的问题:ORA-12154 ...
- 检查class排座位
在写这篇文章之前,xxx已经写过了几篇关于改检查class主题的文章,想要了解的朋友可以去翻一下之前的文章 每日一道理 灯,带有一种明亮的光,每当深夜来临,是它陪伴着你,如此默默无闻.它是平凡 ...
- iOS开发——基本常识篇&各种控件默认高度
各种控件默认高度 1.状态栏 状态栏一般高度为20像素,在打手机或者显示消息时会放大到40像素高,注意,两倍高度的状态栏在好像只能在纵向的模式下使用.如下图 用户可以隐藏状态栏,也可以将状态栏设置 ...
- Java中的NIO和IO的对比分析
总的来说,java中的IO和NIO主要有三点区别: IO NIO 面向流 面向缓冲 阻塞IO 非阻塞IO 无 选择器(Selectors) 1.面向流与面向缓冲 Java NIO和IO之间第一个最大的 ...