当前位置:网站首页>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
边栏推荐
- Fluent fluent library encapsulation
- bellman-ford AcWing 853. Shortest path with side limit
- Performance tuning project case
- 接口测试面试题目,你都会了吗?
- BOM DOM
- [I'm a mound pytorch tutorial] learning notes
- Visual studio efficient and practical extension tools and plug-ins
- 绕过ObRegisterCallbacks需要驱动签名方法
- Js10day (API phased completion, regular expression introduction, custom attributes, filtering sensitive word cases, registration module verification cases)
- Interview questions for software testing - a collection of interview questions for large factories in 2022
猜你喜欢
Drools dynamically add, modify, and delete rules
Record the range of data that MySQL update will lock
async/await 异步函数
Efficiency comparison between ArrayList and LinkedList
浏览器存储方案
What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT
Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold
模块化 CommonJS ES Module
Rust search server, rust quick service finding tutorial
[FFH] little bear driver calling process (take calling LED light driver as an example)
随机推荐
Use sqoop to export ads layer data to MySQL
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
H5 to app
线性DP AcWing 896. 最长上升子序列 II
MySQL and PostgreSQL methods to grab slow SQL
spfa AcWing 852. SPFA judgement negative ring
1380. Lucky numbers in the matrix [two-dimensional array, matrix]
Some sudden program ideas (modular processing)
Deep Copy Event bus
中国交通标志检测数据集
bellman-ford AcWing 853. 有边数限制的最短路
About wechat enterprise payment to change x509certificate2 read certificate information, publish to the server can not access the solution
区间DP AcWing 282. 石子合并
Fluent fluent library encapsulation
Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
Lekao: 22 year first-class fire engineer "technical practice" knowledge points
Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime
Simple use of drools decision table
上手报告|今天聊聊腾讯目前在用的微服务架构