当前位置:网站首页>Linear DP acwing 897 Longest common subsequence
Linear DP acwing 897 Longest common subsequence
2022-07-02 12:43:00 【T_ Y_ F666】
linear DP AcWing 897. Longest common subsequence
Original link
AcWing 897. Longest common subsequence
Algorithm tags
Dynamic programming linear DP
Ideas


Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 1005, INF = 0x3f3f3f3f;
int n,m;
char A[N], B[N];
int f[N][N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
n=read(), m=read();
scanf("%s%s", A+1, B+1);
rep(i, 1, n+1){
rep(j, 1, m+1){
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("%lld", f[n][m]);
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- Dijkstra AcWing 850. Dijkstra求最短路 II
- 考研英语二大作文模板/图表作文,英语图表作文这一篇就够了
- Go learning notes - multithreading
- Introduction to CPU instruction set
- 通过反射执行任意类的任意方法
- Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?
- Writing method of then part in drools
- H5 to app
- Go learning notes - go based interprocess communication
- Mui WebView down refresh pull-up load implementation
猜你喜欢

Floyd AcWing 854. Floyd求最短路

Dijkstra AcWing 850. Dijkstra finding the shortest circuit II

async/await 异步函数

Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?

线性DP AcWing 899. 编辑距离

堆 AcWing 839. 模拟堆

The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night

spfa AcWing 851. SPFA finding the shortest path

There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes

BOM DOM
随机推荐
Performance tuning project case
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
[ybtoj advanced training guide] similar string [string] [simulation]
Hash table acwing 840 Simulated hash table
Is the neural network (pinn) with embedded physical knowledge a pit?
Fluent fluent library encapsulation
. Net, C # basic knowledge
Leetcode - Sword finger offer 37, 38
Redis sentinel mechanism and configuration
The differences and relationships among port, targetport, nodeport and containerport in kubenetes
Efficiency comparison between ArrayList and LinkedList
Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE
js1day(输入输出语法,数据类型,数据类型转换,var和let区别)
BOM DOM
线性DP AcWing 896. 最长上升子序列 II
8A 同步降压稳压器 TPS568230RJER_规格信息
JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
8 examples of using date commands
Sparkcontext: error initializing sparkcontext solution