当前位置:网站首页>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;
}
边栏推荐
- 1330:【例8.3】最少步数
- [recruitment position] Software Engineer (full stack) - public safety direction
- Talk about your understanding of microservices (PHP interview theory question)
- 如何将 DevSecOps 引入企业?
- MySQL表字段调整
- Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
- [recruitment position] infrastructure software developer
- Want to ask the big guy, is there any synchronization from Tencent cloud Mysql to other places? Binlog saved by Tencent cloud MySQL on cos
- Calculate weight and comprehensive score by R entropy weight method
- [JVM] operation instruction
猜你喜欢

DVWA range clearance tutorial

Bugku's steganography

Common redis data types and application scenarios

Crud de MySQL

First PR notes

Huiyuan, 30, is going to have a new owner

Thymeleaf uses background custom tool classes to process text

Optional parameters in the for loop

ionic cordova项目修改插件

Machine learning notes - gray wolf optimization
随机推荐
Crud de MySQL
Bugku's Eval
如何将 DevSecOps 引入企业?
Common interview questions about swoole
GPS original coordinates to Baidu map coordinates (pure C code)
【简记】解决IDE golang 代码飘红报错
Jmeter性能测试:ServerAgent资源监控
当代人的水焦虑:好水究竟在哪里?
Severlet learning foundation
OSI 七层模型
SQL Server learning notes
MySQL之CRUD
The difference between SQL Server char nchar varchar and nvarchar
MySQL之CRUD
JS bright blind your eyes date selector
Redis' transaction mechanism
mapper. Comments in XML files
sql server char nchar varchar和nvarchar的区别
Nine hours, nine people, nine doors problem solving Report
Fr exercise topic --- comprehensive question