当前位置:网站首页>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
边栏推荐
- 8 examples of using date commands
- 趣味 面试题
- 浏览器node事件循环
- JDBC prevent SQL injection problems and solutions [preparedstatement]
- OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
- 软件测试面试题-2022年大厂面试题合集
- PR 2021 quick start tutorial, learn about the and functions of the timeline panel
- Lekao.com: experience sharing of junior economists and previous candidates in customs clearance
- Wechat official account payment prompt MCH_ ID parameter format error
- What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT
猜你喜欢
js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
"As a junior college student, I found out how difficult it is to counter attack after graduation."
JSON序列化 与 解析
Simple understanding of ThreadLocal
浏览器node事件循环
js1day(输入输出语法,数据类型,数据类型转换,var和let区别)
async/await 异步函数
Deep copy event bus
Efficiency comparison between ArrayList and LinkedList
Lekao.com: experience sharing of junior economists and previous candidates in customs clearance
随机推荐
Openssh remote enumeration username vulnerability (cve-2018-15473)
软件测试面试题-2022年大厂面试题合集
考研英语二大作文模板/图表作文,英语图表作文这一篇就够了
C#运算符
深拷贝 事件总线
Sweetheart leader: Wang Xinling
arcgis js 4. Add pictures to x map
. Net, C # basic knowledge
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
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
线性DP AcWing 897. 最长公共子序列
JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
JDBC prevent SQL injection problems and solutions [preparedstatement]
Leetcode - < dynamic planning special> Jianzhi offer 19, 49, 60
JDBC 预防sql注入问题与解决方法[PreparedStatement]
Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
上手报告|今天聊聊腾讯目前在用的微服务架构
Redis sentinel mechanism and configuration
Efficiency comparison between ArrayList and LinkedList