当前位置:网站首页>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 
边栏推荐
- Input box assembly of the shutter package
- NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
- BOM DOM
- Fluent fluent library encapsulation
- Simple understanding of ThreadLocal
- Interview questions for software testing - a collection of interview questions for large factories in 2022
- Hash table acwing 841 String hash
- Sweetheart leader: Wang Xinling
- Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold
- JSON序列化 与 解析
猜你喜欢
![2.6 using recursion and stack - [tower of Hanoi problem]](/img/fc/45038170dafd104691c93716b103cf.jpg)
2.6 using recursion and stack - [tower of Hanoi problem]

传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE

Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold

PR 2021 quick start tutorial, learn about the and functions of the timeline panel

Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)

Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately

堆 AcWing 838. 堆排序

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

Floyd AcWing 854. Floyd求最短路

Execute any method of any class through reflection
随机推荐
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
Simple understanding of ThreadLocal
JDBC 预防sql注入问题与解决方法[PreparedStatement]
Hash table acwing 841 String hash
Sse/avx instruction set and API of SIMD
2.6 using recursion and stack - [tower of Hanoi problem]
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
考研英语二大作文模板/图表作文,英语图表作文这一篇就够了
堆 AcWing 838. 堆排序
Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
C#修饰符
百款拿来就能用的网页特效,不来看看吗?
"As a junior college student, I found out how difficult it is to counter attack after graduation."
Lekao: 22 year first-class fire engineer "technical practice" knowledge points
JSON序列化 与 解析
FBX import under ue4/ue5 runtime
ArrayList与LinkedList效率的对比