当前位置:网站首页>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;
}边栏推荐
- AQS之ReentrantLock源码解析
- TCP/IP五层模型
- 如何描述一个BUG以及BUG级别的定义、生命周期
- OSI七层模型
- 进程和线程的区别
- JS四则运算重新封装,解决精度丢失问题
- 网络——传输层(详细版)
- SSAO by computer shader (I)
- It is recommended to wear air conduction earphones, which do not need to wear in ear
- Redis implementation of distributed lock and analysis of the main process of redismission distributed lock
猜你喜欢

mysql-8.0.17-winx64(附加navicat)手动配置版安装

Prometheus monitoring Nacos

iptables防火墙

Which is the best one to make air conduction headphones? Inventory of the best air conduction headphones

RayMarching realizes volume light rendering

Ten thousand words summarize and realize the commonly used sorting and performance comparison
![[untitled]](/img/54/660667e528729cc87796d972dc0b17.png)
[untitled]

mongoDB复制集及分片集群

AQS之ReentrantLock源码解析

Analysis of the semaphore source code of AQS
随机推荐
测试面试题集锦(二)| 测试工具篇(附答案)
yapi漏洞挂马程序chongfu.sh处理
RayMarching实现体积光渲染
---栈&队列---
Redis implementation of distributed lock and analysis of the main process of redismission distributed lock
软件开发中常见模型
单元测试框架Jest搭配TypeScript的安装与配置
JS四则运算重新封装,解决精度丢失问题
Brief analysis of order transaction
Which brand of air conduction earphones is better? These four should not be missed
HDU-2036-改革春风吹满地(多边形面积模板)
[dynamic planning -- the best period for buying and selling stocks Series 2]
Leetcode skimming diary sword finger offer II 050. sum of downward path nodes
代码整洁之道(二)
浅谈Cookie和Session
测试面试题集锦(一)| 软件测试常见必考问题与流程篇(附答案)
技术分享 | 接口自动化测试中,如何做断言验证?
rancher部署实战
Analysis of cyclicbarrier source code of AQS
Compilation and preprocessing of C language