当前位置:网站首页>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 
边栏推荐
- 防抖 节流
- Openssh remote enumeration username vulnerability (cve-2018-15473)
- 染色法判定二分图 AcWing 860. 染色法判定二分图
- Introduction to CPU instruction set
- MySQL and PostgreSQL methods to grab slow SQL
- Day12 control flow if switch while do While guessing numbers game
- PR 2021 quick start tutorial, learn about the and functions of the timeline panel
- Execute any method of any class through reflection
- 线性DP AcWing 897. 最长公共子序列
- Do you know all the interface test interview questions?
猜你喜欢

spfa AcWing 851. spfa求最短路
![[ybtoj advanced training guidance] judgment overflow [error]](/img/be/bbe357ac2f2a8839afc5af47db88d0.jpg)
[ybtoj advanced training guidance] judgment overflow [error]

What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT

Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)

Bom Dom

Dijkstra AcWing 850. Dijkstra finding the shortest circuit II

C#运算符

高性能纠删码编码

JSON序列化 与 解析

Use sqoop to export ads layer data to MySQL
随机推荐
BOM DOM
Redis sentinel mechanism and configuration
Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
Execute any method of any class through reflection
基于STM32的OLED 屏幕驱动
Lekao.com: experience sharing of junior economists and previous candidates in customs clearance
What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT
防抖 节流
Rust语言文档精简版(上)——cargo、输出、基础语法、数据类型、所有权、结构体、枚举和模式匹配
Drools executes string rules or executes a rule file
Js10day (API phased completion, regular expression introduction, custom attributes, filtering sensitive word cases, registration module verification cases)
Simple use of drools decision table
Bom Dom
China traffic sign detection data set
[I'm a mound pytorch tutorial] learning notes
Wechat official account payment prompt MCH_ ID parameter format error
Intel internal instructions - AVX and avx2 learning notes
async/await 异步函数
Openssh remote enumeration username vulnerability (cve-2018-15473)
Lekao: 22 year first-class fire engineer "technical practice" knowledge points