当前位置:网站首页>POJ - 1458 common subsequence (longest common subsequence)
POJ - 1458 common subsequence (longest common subsequence)
2022-07-02 17:42:00 【WA_ automata】
POJ - 1458 Common Subsequence( Longest common subsequence )
Description
A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, …, xm > another sequence Z = < z1, z2, …, zk > is a subsequence of X if there exists a strictly increasing 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.
Input
The program input is from the std input. Each data set in the input contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct.
Output
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.
Sample Input
abcfbc abfcab
programming contest
abcd mnp
Sample Output
4
2
0
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 1010;
char a[N],b[N];
int main()
{
while(scanf("%s%s",a+1,b+1)!=EOF)
{
int n=strlen(a+1),m=strlen(b+1);
int f[n+1][m+1];
memset(f,0,sizeof f);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
f[i][j]=max(f[i-1][j],f[i][j-1]);
if(a[i]==b[j]) f[i][j]=max(f[i][j],f[i-1][j-1]+1);
}
printf("%d\n",f[n][m]);
}
return 0;
}
边栏推荐
- [fluent] dart data type map type (create map set | initialize map set | traverse map set)
- 从收集到输出:盘点那些强大的知识管理工具——优秀笔记软件盘点(四)
- No such file or directory: ‘/tmp/tmpxxx/tmpxxx.py‘
- Configure lamp+supervisor
- Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
- SAP commerce cloud storefront framework selection: accelerator or Spartacus?
- After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
- Baobab's gem IPO was terminated: Tang Guangyu once planned to raise 1.8 billion to control 47% of the equity
- TCP congestion control details | 2 background
- OpenHarmony如何启动FA(本地和远程)
猜你喜欢

Microservice architecture practice: Construction of scalable distributed database cluster

freemarker+poi实现动态生成excel文件及解析excel文件

Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?

每日一题——小乐乐改数字

【网络是怎样连接的】第五章 探索服务器

chrome浏览器快速访问stackoverflow

VirtualLab基础实验教程-7.偏振(2)

Use of nexttile function in MATLAB

Map集合详细讲解
![List summation [dummy+ tail interpolation + function processing list reference common pit]](/img/08/30e8ca2376104d648a82dca8a72c42.png)
List summation [dummy+ tail interpolation + function processing list reference common pit]
随机推荐
This "architect growth note" made 300 people successfully change jobs and enter the big factory, with an annual salary of 50W
uva1169
Configure lamp+supervisor
Alibaba Tianchi SQL learning notes - Day3
easyAI笔记——深度学习
How openharmony starts fa (local and remote)
The beginning of life
Simple linear programming problem
Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)
[how is the network connected] Chapter 4 explores access networks and network operators
Common SQL statements (complete example)
What is agile development process
SAP commerce Cloud Architecture Overview
helm kubernetes包管理工具
easyswoole3.2重启不成功
Ocio V2 reverse LUT
Example nonlinear integer programming
关于我
Leetcode question brushing record | 933_ Recent requests
Idea2021.1 installation tutorial