HDU1159-Common Subsequence-LCS
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 39661 Accepted Submission(s): 18228
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.
题意就是求两个字符串的最长公共子序列的长度。
LCS入门,传送门1:http://blog.csdn.net/liufeng_king/article/details/8500084
传送门2:http://blog.csdn.net/orbit/article/details/6717125
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+;
char s1[N],s2[N];
int dp[N][N];
int len1,len2;
void fun(){
memset(dp,,sizeof(dp));
for(int i=;i<=len1;i++){
for(int j=;j<=len2;j++){
if(s1[i-]==s2[j-])
dp[i][j]=dp[i-][j-]+;
else
dp[i][j]=max(dp[i-][j],dp[i][j-]);
}
}
}
int main(){
while(~scanf("%s%s",&s1,&s2)){
len1=strlen(s1);
len2=strlen(s2);
fun();
printf("%d\n",dp[len1][len2]);
}
return ;
}
HDU1159-Common Subsequence-LCS的更多相关文章
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- HDU1159 && POJ1458:Common Subsequence(LCS)
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- Common Subsequence LCS
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/F 题目: Description A subsequ ...
- 最长公共字串算法, 文本比较算法, 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(LCS)
一.Description A subsequence of a given sequence is the given sequence with some elements (possible n ...
- HDU-1159 Common Subsequence 最长上升子序列
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 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:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- 解题报告:hdu1159 common consequence LCS裸题
2017-09-02 17:07:42 writer:pprp 通过这个题温习了一下刚学的LCS 代码如下: /* @theme:hdu1159 @writer:pprp @begin:17:01 @ ...
- Longest Common Subsequence (LCS)
最长公共子序列(LCS)是经典的DP问题,求序列a[1...n], b[1..m]的LCS. 状态是DP[i][j],表示a[1..i],b[1..j]的LCS. DP转移方程是 DP[i][j]= ...
随机推荐
- Function:html结构转字符串形式显示
//Html结构转字符串形式显示 支持<br>换行 function ToHtmlString(htmlStr) { return toTXT(htmlStr).replace(/\&am ...
- iOS 环信透传cmd消息多次重复接收,解决办法
由于项目需求,需要在项目中接到消息的时候做不同界面的不同的操作,哪儿需要哪儿就要添加代理:引起代理事件重复执行:所以要在VC显示的时候添加代理,消失的时候删除代理 环信 透传 消息多次接收情况(由于代 ...
- SQL Server 数据库引擎怎样记录完整备份后修改过的数据
SQL Server 使用两个内部数据结构跟踪被大容量复制操作修改的区,以及自上次完整备份后修改的区.这些数据结构极大地加快了差异备份的速度.当数据库使用大容量日志恢复模式时,这些数据结构也可以加快将 ...
- Handler的解析和使用
1.handler为android中多线程间通信的一种机制, @1android中只允许在UI线程(主线程)操作或改变UI,其他线程不能操作UI. @2其他线程有刷新UI的需要,所以得告诉UI线程,这 ...
- adb指令介绍
一.adb命令格式为:adb [-d|-e|-s <serialNumber>] <command> 1.adb devices :列出当前电脑所连接的所有安卓设备 2.adb ...
- 转战Hexo
从之前的转战farbox,到现在又转战Hexo,真是不折腾不成魔.要说farbox有什么不好,可能唯一的不好就是它要求与Dropbox关联吧,这对于大部分国内用户来说是无法接受的,写文章之前一想到还要 ...
- Python学习(一):编写购物车
1.购物车流程图: 2.代码实现: #!/usr/bin/env python #coding=utf-8 ChoiceOne =''' 1.查看余额 2.购物 3.退出 ''' ChoiceTwo ...
- js 深入理解原型模式
我们创建每一个函数都有一个prototype(原型)属性,这个属性是一个指针,指向一个对象.使用原型的好处是可以让所有对象共享它所包含的属性和方法. function Person(){ } Pers ...
- Webservice接口的调用
一.开发webservice接口的方式 1.jdk开发. 2.使用第三方工具开发,如cxf.shiro等等. 我这边介绍jdk方式webservice接口调用. 二.使用jdk调用webservice ...
- 如何使用MOQ进行单元测试
使用MOQ来伪装和隔离被依赖对象,从而提高被测对象的测试效果. 安装 通过http://code.google.com/p/moq可以下载MOQ的最新版本.在SSL项目中,我们使用的是MOQ 3.1. ...