当前位置:网站首页>线性DP AcWing 897. 最长公共子序列
线性DP AcWing 897. 最长公共子序列
2022-07-02 09:43:00 【T_Y_F666】
线性DP AcWing 897. 最长公共子序列
原题链接
算法标签
动态规划 线性DP
思路
代码
#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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Drools dynamically add, modify, and delete rules
- MySQL indexes and transactions
- CPU指令集介绍
- Use sqoop to export ads layer data to MySQL
- 使用Sqoop把ADS层数据导出到MySQL
- (C language) octal conversion decimal
- Leetcode209 subarray with the smallest length
- Anti shake throttle
- Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
- Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime
猜你喜欢
Mysql database foundation
2.7 binary tree, post order traversal - [FBI tree]
记录一下MySql update会锁定哪些范围的数据
What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT
Performance tuning project case
寻找二叉树中任意两个数的公共祖先
Docker-compose配置Mysql,Redis,MongoDB
5g era, learning audio and video development, a super hot audio and video advanced development and learning classic
mysql索引和事务
[ybtoj advanced training guide] similar string [string] [simulation]
随机推荐
Record the range of data that MySQL update will lock
SparkContext: Error initializing SparkContext解决方法
FBX import under ue4/ue5 runtime
Those logs in MySQL
Jenkins voucher management
(C language) octal conversion decimal
Map和Set
Sub thread get request
[C language] Yang Hui triangle, customize the number of lines of the triangle
BOM DOM
LeetCode—<动态规划专项>剑指 Offer 19、49、60
Sparkcontext: error initializing sparkcontext solution
MySQL与PostgreSQL抓取慢sql的方法
IPhone 6 plus is listed in Apple's "retro products" list
Input box assembly of the shutter package
深拷贝 事件总线
浏览器存储方案
Lekao.com: experience sharing of junior economists and previous candidates in customs clearance
Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间