当前位置:网站首页>Hdu-1159-commonsubsequence (LCS longest common subsequence)
Hdu-1159-commonsubsequence (LCS longest common subsequence)
2022-07-28 06:51:00 【__ Simon】
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 34353 Accepted Submission(s): 15683
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
LCS- Longest common subsequence
#include <cstdio>
#include <cstring>
int a[1010][1010];
int LCS(char *s1,char *s2){
int m=strlen(s1),n=strlen(s2);
int i,j;
a[0][0]=0;
for(i=1;i<=m;i++) a[i][0]=0;
for(i=1;i<=n;i++) a[0][i]=0;
for(i=1;i<=m;i++){
for(j=1;j<=n;j++){
if(s1[i-1]==s2[j-1]) a[i][j] = a[i-1][j-1]+1;
else if(a[i-1][j]>a[i][j-1]) a[i][j]=a[i-1][j];
else a[i][j]=a[i][j-1];
}
}
return a[m][n];
}
char s1[1010],s2[1010];
int main(){
//freopen("in.txt","r",stdin);
while(~scanf("%s%s",s1,s2)){
printf("%d\n",LCS(s1,s2));
}
return 0;
}边栏推荐
- ZOJ Problem 1005 jugs
- 项目编译NoSuch***Error问题
- Brief analysis of order transaction
- Leetcode brush questions diary sword finger offer II 047. Binary tree pruning
- HDU-1097-A hard puzzle(快速幂)
- Source code analysis of countdownlatch of AQS
- MySQL index optimization
- Which brand of air conduction earphones is good and highly praised
- Qgraphicsview promoted to qchartview
- Scratch command
猜你喜欢

Battle plague Cup -- strange shape

Skimming records -- sequence traversal of binary tree

Analysis of cyclicbarrier source code of AQS
![[dynamic planning -- the best period for buying and selling stocks series 3]](/img/9f/f6c07264f5ffaa0fdfcc724c713e83.png)
[dynamic planning -- the best period for buying and selling stocks series 3]

AQS之ReentrantLock源码解析

技术分享 | 接口测试常用代理工具

Centos7 deploy MySQL database server

RayMarching实现体积光渲染

Leetcode brush question diary sword finger offer II 048. serialization and deserialization binary tree

Personal understanding of Chinese remainder theorem
随机推荐
测试面试题集锦(三)| 计算机网络和数据库篇(附答案)
rancher部署实战
InitializingBean接口及示例
[pta ---- traversal of tree]
Rain Scene Effect (I)
测试面试题集锦(二)| 测试工具篇(附答案)
AQS之semaphore源码分析
[dynamic planning -- the best period for buying and selling stocks Series 2]
技术分享 | 接口自动化测试中,如何做断言验证?
mongoDB复制集及分片集群
Question brushing record - linked list
QGraphicsView提升为QChartView
Qgraphicsview promoted to qchartview
What's a good gift for Tanabata? Niche and advanced product gift recommendation
Leetcode skimming diary sword finger offer II 050. sum of downward path nodes
MySQL主主
elastic常用高频命令
PKU-2524-Ubiquitous Religions(并查集模板)
Source code analysis of countdownlatch of AQS
[dynamic planning -- the best period series for buying and selling stocks]