hdu 1159(Common Subsequence)简单dp,求出最大的公共的字符数
Common Subsequence
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.
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>
int i,j;
int c[1010][1010];//c数组用来表示对于n,m,的 两个字符串。最大公共字符数
char a[1010],b[1010];//用来存储两个字符串
int lcs(int n,int m)
{
memset(c,0,sizeof(c));//初始化
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(a[i-1]==b[j-1])//两者同样的时候,就是在原来的基础上再加一
c[i][j]=c[i-1][j-1]+1;
else
c[i][j]=c[i-1][j]>c[i][j-1]? c[i-1][j]:c[i][j-1];//两者不同九江前面的两个字符串中的存储的最大的公共字符数存储在c[i][j]里
}
}
return c[n][m];//返回n个字符,m个字符的最大的公共字符数
}
int main()
{
while(~scanf("%s %s",a,b))
{
i=strlen(a);
j=strlen(b);
printf("%d\n",lcs(i,j));
}
return 0;
}
hdu 1159(Common Subsequence)简单dp,求出最大的公共的字符数的更多相关文章
- 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)
题目链接 Problem Description A subsequence of a given sequence is the given sequence with some elements ...
- hdu 1159 Common Subsequence (dp乞讨LCS)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1159——Common Subsequence(DP)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 题解 #include<iostream> #include<cstring> ...
- HDU 1159 Common Subsequence
HDU 1159 题目大意:给定两个字符串,求他们的最长公共子序列的长度 解题思路:设字符串 a = "a0,a1,a2,a3...am-1"(长度为m), b = "b ...
- HDU 1159 Common Subsequence 最长公共子序列
HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
- 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(最长公共子序列 DP)
题目链接: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 ...
随机推荐
- HDU 1754.I Hate It-完全版线段树(单点替换、区间最值)
HDU1754.I Hate It 直接模板就可以了 代码: //B #include<iostream> #include<cstdio> #include<cstri ...
- SpringCloud集群(三)
一.构造步骤 1.进行其他的服务中心的域名映射 127.0.0.1 eureka7001.com 127.0.0.1 eureka7002.com 127.0.0.1 eureka7003.com 2 ...
- SpringBoot日志管理
一.简介 小张:开发一个大型系统:1.System.out.println(""):将关键数据打印在控制台:去掉?写在一个文件?2.框架来记录系统的一些运行时信息:日志框架 : z ...
- FZU-2214 Knapsack problem(DP使用)
Problem 2214 Knapsack problem Accept: 863 Submit: 3347Time Limit: 3000 mSec Memory Limit : 327 ...
- RandomeAccessFile - read write
RandomeAccessFile use write replace writeBytes public class RandomAccessFileTest { public static voi ...
- teamviewer13报错
用自己的笔记本电脑远程桌面AGV电脑在终端运行teamviewer报错如下: Init...CheckCPU: SSE2 support: yesChecking setup...Launching ...
- 【bzoj1566】【管道取珠】竟然是dp题(浅尝ACM-E)
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=61891436 向大(hei)佬(e)势力学(di ...
- Nand flash uboot 命令详解
转:http://blog.chinaunix.net/uid-14833587-id-76513.html nand info & nand device 显示flash的信息: DM365 ...
- crossapp的屏幕适配
1.分辨率是的某个尺寸大小的屏幕里的像素点数ppi 2.crossapp茶用iphone4为基准比例值为1 3.其它分辨率设备的换算dp = px * 320/ 屏幕PPI 4.crossapp里点. ...
- 在pos:a元素不设定宽度的情况下,他的最大宽度是受父元素的宽度所限制的。
<div style="width:80px;height:50px;position:relative;left:50px;"> <ul style=" ...