hdoj 1159 Common Subsequence【LCS】【DP】
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28494 Accepted Submission(s): 12735
..., 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<stdio.h>
#include<string.h>
#define max(a,b) (a>b? a:b)
char a[1000],s[1000];
int dp[1000][1000];
int main()
{
int i,j,k;
while(scanf("%s%s",a,s)!=EOF)
{
memset(dp,0,sizeof(dp));
int l=strlen(a);
int le=strlen(s);
for(i=1;i<=l;i++)
{
for(j=1;j<=le;j++)
if(a[i-1]==s[j-1])//推断左側和上側字符是否相等
dp[i][j]=dp[i-1][j-1]+1;//把左上側的dp值+1
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);//取左側或上側的最大dp值
}
printf("%d\n",dp[l][le]);
}
return 0;
}
hdoj 1159 Common Subsequence【LCS】【DP】的更多相关文章
- HDOJ 1159 Common Subsequence【DP】
HDOJ 1159 Common Subsequence[DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1159 Common Subsequence(裸LCS)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- hdu 1159 Common Subsequence(最长公共子序列 DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- HDOJ --- 1159 Common Subsequence
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Hdoj 1159.Common Subsequence 题解
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- hdu 1159 Common Subsequence(LCS)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1159 Common Subsequence:LCS(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 题意: 求最长公共子序列. 题解: (LCS模板题) 表示状态: dp[i][j] = max ...
- hdu 1159 Common Subsequence(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- HDU 1159 Common Subsequence
HDU 1159 题目大意:给定两个字符串,求他们的最长公共子序列的长度 解题思路:设字符串 a = "a0,a1,a2,a3...am-1"(长度为m), b = "b ...
随机推荐
- C++友元(Friend)简介
相对Java而言,友元是C++中特有的一种元素,再加上<C++ Primer>也并没有太具体的样例,所以刚接触这个概念的时候懵了非常久,即是自己总结一下,也希望能帮到大家,以下来讲讲友元的 ...
- angularjs 模块化
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- ssh跳板登陆太麻烦,使用expect每次自动登录 利用expect 模拟键盘动作,在闲置时间之内模拟地给个键盘响应
#!/usr/bin/expect -f #设置超时时间 set timeout #这里设置了跳板机的密码 set password "你的跳板机密码" #连接跳板机 spawn ...
- BZOJ 2049 LCT
思路:LCT的基本操作 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm&g ...
- TabLayout中Indicator的样式修改
最近写一个项目的时候用到了TabLayout,其中Indicator只是固定的一条横线,样式只能修改Color和Height,没有办法改变形状和宽度等其他信息. 经过查看TabLayout类的源码,发 ...
- UI Framework-1: Browser Window
Browser Window The Chromium browser window is represented by several objects, some of which are incl ...
- JAVA版本区块链钱包核心代码
Block.java package com.ppblock.blockchain.core; import java.io.Serializable; /** * 区块 * @author yang ...
- shell脚本不同运行方式的差异
说明:以下是个人的见解,不一定都正确,如有错误,欢迎指正! 一,shell脚本的运行方式,最常见的有以下几种: 1 ) . xxx.sh,注意,前面是一个点'.' 2 ) source xxx.sh ...
- docker操作大全
docker 常用操作方法 查看docker版本docker version 搜索镜像docker serach 镜像名称 拉去镜像docker pull 镜像名称 查看本地镜像仓库信息docker ...
- python、js 时间日期模块time
python 参考链接:https://www.runoob.com/python/python-date-time.html 时间戳 >>> print(time.time())# ...