HDU 1159 Common Subsequence 公共子序列 DP 水题重温
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18201 Accepted Submission(s): 7697
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.
解题思路:
开一个二维数组f[N][M]记录第一个数组取前N个数和第二个数组取前M个数的时候公共子序列的最大长度,最后输出f[l1][l2]即为最后结果。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char keng1[],keng2[];
int con[][];
int getmax(int a,int b)
{if(a>b)return a;else return b;}
int main()
{
int i,j,l1,l2,Max;
keng1[]=keng2[]='#';
while(scanf("%s%s",keng1+,keng2+)!=EOF)
{
Max=;
l1=strlen(keng1);
l2=strlen(keng2);
memset(con,,sizeof(con));
for(i=;i<l1;i++)
{
for(j=;j<l2;j++)
{
if(keng1[i]==keng2[j])
con[i][j]=getmax(con[i][j],con[i-][j-]+);
else
con[i][j]=getmax(con[i-][j],con[i][j-]);
}
}
printf("%d\n",con[l1-][l2-]);
}
return ;
}
HDU 1159 Common Subsequence 公共子序列 DP 水题重温的更多相关文章
- HDU 1159.Common Subsequence【动态规划DP】
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- HDU 1159 Common Subsequence 最长公共子序列
HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
- HDU 1159 Common Subsequence
HDU 1159 题目大意:给定两个字符串,求他们的最长公共子序列的长度 解题思路:设字符串 a = "a0,a1,a2,a3...am-1"(长度为m), b = "b ...
- hdu 1159 Common Subsequence(最长公共子序列 DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- 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(裸LCS)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- HDU 1159 Common Subsequence【dp+最长公共子序列】
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1159 Common Subsequence --- DP入门之最长公共子序列
题目链接 基础的最长公共子序列 #include <bits/stdc++.h> using namespace std; ; char c[maxn],d[maxn]; int dp[m ...
- hdu 1159 Common Subsequence(最长公共子序列,DP)
题意: 两个字符串,判断最长公共子序列的长度. 思路: 直接看代码,,注意边界处理 代码: char s1[505], s2[505]; int dp[505][505]; int main(){ w ...
随机推荐
- jQuery设置checkbox全选(区别jQuery版本)
jQuery设置checkbox全选在网上有各种文章介绍,但是为什么在我们用他们的代码的时候就没有效果呢? 如果你的代码一点错误都没有,先不要急着怀疑人家代码的正确性,也许只是人家跟你用的jQuery ...
- CentOS 6.4 通过Yum给Chrome安装Adobe Flash Player
方法一:安装 Flash Player yum install flash-plugin 安装好后,重新启动chrome,在地址栏输入[chrome://plugins/]确定 Shockware F ...
- python入门 第二天笔记
程序主文件标志if __name__=="__main__": 在程序执行python 1.py 时候 程序1.py __name__ 为 main调用其他文件是,__name__ ...
- Navigation学习笔记
***************************** 使用storyboard导航********************************* storyboard方式相对简单. 在弹出来 ...
- RESTheart安装与设置
作者:Maurizio Turatti, 最后在Feb 25, 2016时被 Andrea Di Cesare更新 安装与设置 1. 快速开始 Docker Vagrant Bare metal 2. ...
- skiplist 跳表(2)-----细心学习
快速了解skiplist请看:skiplist 跳表(1) http://blog.sina.com.cn/s/blog_693f08470101n2lv.html 本周我要介绍的数据结构,是我非常非 ...
- [wikioi]乌龟棋
http://wikioi.com/problem/1068/ 多重背包.边界f[0,0,0,0]=a[1](初始时没有用任何卡片,获得棋盘第一格的分数)DP方程:f[i,j,k,l]=max(f[i ...
- [mock]10月11日
第二次mock.出的题是,假设有一个地区不能使用7,都用之后的数字代替,比如8代表7,18代表16(中间有7和17).那么给出一个这个地区的数X,求普通地区的数Y.首先是找规律,发现其实就是找给出的数 ...
- 【Xamarin挖墙脚系列:Xamarin.IOS的程序的结构】
原文:[Xamarin挖墙脚系列:Xamarin.IOS的程序的结构] 开始熟悉Xamarin在开发IOS的结构!!!!!!! 先看官方 这个是以一个单页面的程序进行讲述的. 1 程序引用的程序集,核 ...
- Android Bitmap是不能比较的,这样做是错误的
代码1: Bitmap dir = BitmapFactory.decodeResource(context.getResources(), R.drawable.netdisc_search_lis ...