当前位置:网站首页>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;
}边栏推荐
猜你喜欢

技术分享 | 服务端接口自动化测试, Requests 库的这些功能你了解吗?

软件开发中常见模型

Leetcode brush questions diary sword finger offer II 047. Binary tree pruning

KVM热迁移

archery数据库审核平台部署

Analysis of reentrantlock source code of AQS

SSAO by computer shader (I)

Personal understanding of Chinese remainder theorem

yapi漏洞挂马程序chongfu.sh处理

redis实现分布式锁思路及redission分布式锁主流程分析
随机推荐
遍历 二叉树
What kind of air conduction Bluetooth headset with good configuration is recommended
---栈&队列---
Which is the best and most cost-effective air conduction headset recommended
Question skimming record - hash table
测试人生 | 二线城市年薪超40W?疫情之下涨薪100% + 是怎么做到的?
Ubuntu18.04搭建redis集群【学习笔记】
Dynamic memory management function of C language
Qgraphicsview promoted to qchartview
Array solution script
数组转链表
手把手教你三步完成测试监控系统搭建
Compilation and preprocessing of C language
Using C language to realize three piece chess games
[C language] custom structure type
HDU-2036-改革春风吹满地(多边形面积模板)
[dynamic planning -- the best period series for buying and selling stocks]
搭建PHP7私有仓库
Redis implementation of distributed lock and analysis of the main process of redismission distributed lock
Redis cache design and performance optimization