当前位置:网站首页>Maximum common subsequence
Maximum common subsequence
2022-07-05 15:26:00 【Xuanhong Zhou】
Actually , I'm already in linear dp This topic has been updated there
The purpose of rewriting here , I really want to roast
why??
I'm really dry today
I would like to ask if the university is not a real place to learn knowledge , Give me some messy hubby classes , Finish some meaningless hobby homework , A development project , Just follow the manual , It's the same as installing the software according to the instructions , Is it helpful for me ??? I have to thank my roommate and my classmates here , It's them help My homework , Let me not make these hobbit things every day , I can find time to do what I want to do , Learn the real , Helpful , Wonderful science . Although just a beginner , I also believe that I can gain something , I hope I can become a person like teachers in the future . A recent paper , Now it's written part Some difficulties , Although it is only a summary , But the process of writing an overview is really more painful than a technical article , Suffering from the pain that I can't seem to learn anything , You have to keep checking the information , I want to finish this paper independently , It is estimated that you may have to look at at at least 500 or 600 articles , To quote more than 100 articles , Come on! !
Then I have to write a report , A total of more than ten pages , Not much at all , Hands won't be tired , Because I'm unconscious .
And in class , Model electricity makes my nerves weak , I don't want to see it every day , Always push and drag tomorrow , Shall I watch it tomorrow ? I still don't watch . But I must watch it later ! Big things have to be reviewed , Tomorrow's exam ! Speechless ! Put in a word , Big stuff seems useless for my future study .
Level 6 preparation is rotten , In fact, now 560+ Maybe enough ? But you have to be prepared for nothing , I'm going to prepare this time , I have to take the exam next semester anyway
That's all , Typing is quite cool , Let's take a look at the heavy fog and model electricity again tonight ,vpn If I can't get in, I can't get on Google scholar ah !
Come on! !( It looks like a sprint )
subject
On the largest common word sequence See linearity by yourself dp That article !!!! I like that article very much , Why are there so few visitors metaverse That article has reached 1200 many , It's really popular metaverse!
Code
/* Given two lengths, they are N and M String A and B Seeking both A The subsequence of is B What is the longest string length of the subsequence of . Input format The first line contains two integers N and M. The second line contains a length of N String , Representation string A. The third line contains a length of M String , Representation string B. Strings are made up of lowercase letters . */
/* Be careful : Here is the public sequence , Not substring , Not necessarily adjacent One 、 State means dp[i][j] Express a Before i and b Before j A set of common sequences dp[i][j] The value of is the maximum length of these common sequences Two 、 State transition equation For a dp[i][j], We need to divide By the end of a[i] And the b[j] Elements Four situations : a[i] Packages are not included in the longest common sequence (0,1) b[j] Packages are not included in the longest common sequence (0,1) 1. 00 dp[i][j]=dp[i-1][j-1] #2 and 3 Want to review the online class 2. 01 dp[i-1][j] 3. 10 dp[i][j-1] 4. 11 Satisfy a[i]=b[j] dp[i][j]=dp[i-1][j-1]+1 */
#include<iostream>
using namespace std;
const int Num=2000;
int N,M;
char a[Num],b[Num];
int dp[Num][Num];
int main(){
cin>>N>>M;
getchar();
for(int i=1;i<=N;i++)
scanf("%c",&a[i]);
getchar();
for(int i=1;i<=M;i++)
scanf("%c",&b[i]);
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++){
if(a[i]==b[j])
dp[i][j]=dp[i-1][j-1]+1;
else
dp[i][j]=max(dp[i-1][j-1],max(dp[i-1][j],dp[i][j-1]));
}
cout<<dp[N][M]<<endl;
return 0;
}
边栏推荐
- lvgl 显示图片示例
- Bugku's Ping
- Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
- wxml2canvas
- 把 ”中台“ 的思想迁移到代码中去
- DVWA range clearance tutorial
- Calculate weight and comprehensive score by R entropy weight method
- Summary of the third class
- [recruitment position] infrastructure software developer
- [JVM] operation instruction
猜你喜欢
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Crud de MySQL
Common MySQL interview questions
当代人的水焦虑:好水究竟在哪里?
Creation and optimization of MySQL index
Reasons and solutions for redis cache penetration and cache avalanche
I spring web upload
keep-alive
Fr exercise topic --- comprehensive question
Transfer the idea of "Zhongtai" to the code
随机推荐
sql server char nchar varchar和nvarchar的区别
Cartoon: programmers don't repair computers!
Redis' transaction mechanism
Anti shake and throttling
漫画:程序员不是修电脑的!
What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Creation and use of thymeleaf template
How to introduce devsecops into enterprises?
JS topic - console log()
Nine hours, nine people, nine doors problem solving Report
The difference between SQL Server char nchar varchar and nvarchar
OSI 七层模型
Redis distributed lock principle and its implementation with PHP (2)
Ctfshow web entry information collection
Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
Your childhood happiness was contracted by it
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
Ionic Cordova project modification plug-in
Anaconda uses China University of science and technology source