C - Common Subsequence
C - Common Subsequence
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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.
Input
abcfbc abfcab
programming contest
abcd mnp
Output
4
2
0
Sample Input
abcfbc abfcab
programming contest
abcd mnp
Sample Output
4
2
0 //求两个字符串的最长公共子序列长度 //虽然是 dp 序列水题,但是我第一次做不会,没想到转移方程 代码里写的很清楚了,31ms dp[i][j]表示0到i-1跟0到j-1的最长公共子序列长度
#include <stdio.h>
#include <string.h> char a[];
char b[];
int dp[][]; int max(int x,int y)
{return x>y?x:y;} int main()
{
int i,j;
while(scanf("%s%s",a,b)!=EOF)
{
int la=strlen(a),lb=strlen(b);
for (i=;i<=lb;i++)
dp[][i]=;
for (i=;i<=la;i++)
dp[i][]=;
for (i=;i<=la;i++)
{
for (j=;j<=lb;j++)
{
if (a[i-]==b[j-])
dp[i][j]=dp[i-][j-]+;
else
dp[i][j]=max(dp[i-][j],dp[i][j-]);
}
}
printf("%d\n",dp[la][lb]);
}
return ;
}
C - Common Subsequence的更多相关文章
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- LintCode Longest Common Subsequence
原题链接在这里:http://www.lintcode.com/en/problem/longest-common-subsequence/ 题目: Given two strings, find t ...
- [UCSD白板题] Longest Common Subsequence of Three Sequences
Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...
- LCS(Longest Common Subsequence 最长公共子序列)
最长公共子序列 英文缩写为LCS(Longest Common Subsequence).其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已 ...
- Longest Common Subsequence
Given two strings, find the longest common subsequence (LCS). Your code should return the length of ...
- LCS POJ 1458 Common Subsequence
题目传送门 题意:输出两字符串的最长公共子序列长度 分析:LCS(Longest Common Subsequence)裸题.状态转移方程:dp[i+1][j+1] = dp[i][j] + 1; ( ...
- Common Subsequence LCS
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/F 题目: Description A subsequ ...
- poj 1458 Common Subsequence
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 46387 Accepted: 19 ...
- Longest Increasing Common Subsequence (LICS)
最长上升公共子序列(Longest Increasing Common Subsequence,LICS)也是经典DP问题,是LCS与LIS的混合. Problem 求数列 a[1..n], b[1. ...
- Common Subsequence(dp)
Common Subsequence Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 951 Solved: 374 Description A subs ...
随机推荐
- Nginx 服务并发过10万的Linux内核优化配置
以下Linux 系统内核优化配置均经在线业务系统测试,服务器运行状态良好,用了一些时间整理,现和大家分享一下,如有那位高人看到配置上有问题,请给与指出! # Controls the use of T ...
- java GC optimization, G1GC
引用 http://www.avricot.com/blog/?post/2010/05/03/Get-started-with-java-JVM-memory-(heap%2C-stack%2 ...
- Java学习之泛型和异常
泛型 1,设计原则或目的:只要代码在编译的时候没有错误,就不会抛异常. 2,泛型通配符 :类型通配符一般是使用 ? 代替具体的类型实参.注意了,此处是类型实参,而不是类型形参!相当于(父类作用)L ...
- nginx资源争夺问题
nginx资源争夺问题 多个配置之间存在资源争夺的情况,需要进行整理: 学习了:https://blog.csdn.net/veryisjava/article/details/72917894 ng ...
- Elasticsearch 基础使用
使用 cURL 执行 REST 命令 可以对 Elasticsearch 发出 cURL 请求,这样很容易从命令行 shell 体验该框架. “Elasticsearch 是无模式的.它可以接受您提供 ...
- 迁移Veil:手工打造Windows下编译的免杀Payload
作者:RedFree 本文转自乌云 Veil对Payload的免杀已经做的很好了,最新的Veil有39个可用的Payload.但是有时候需要使用Windows来完成所有的渗透测试工作,Linux和Wi ...
- eclipse 内存配置
-server -Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256m -XX:+UseG1GC
- 【Datastage】Datastage在win10上安装报错:This Application requires one of the following versions of the .NET Framework:v1.1.4322 Do you want to install this .NET Framework version now?
Datastage在win10上安装报错如下: 这个错误的意思是:.netFramWork的版本不符合要求,于是,我在网上下载了一个版本一致的 下载地址为:http://pan.baidu.com/s ...
- Linux 查看某个程序所在端口的 PID
lsof -i:8085 加入显示的是2001 kill 2001 就可以杀死程序了
- 匿名函数 invoke
delegate string MyDele(string str); string MyFun(string str) { return str; } private void Form1_Load ...