当前位置:网站首页>[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
2022-07-03 21:57:00 【muse_ age】

dp[i][j]: At the same time nums[i] The end and nums[j] Longest increasing common subsequence at the end
initialization :
dp[0][j]=0 dp[j][0]=0
State transition equation :
nums[i]!=nums[j] dp[i][j]=0
nums[i]==nums[j]
dp[i][j]=max(dp[k][l])+1,nums[k]==nums[l] 0<=k<i ,0<=l<j
Time complexity O(N^4)
#include<iostream>
using namespace std;
int n,m;
int num1[4];
int num2[3];
int dp[4][3];
void input(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>num1[i];
}
for(int i=1;i<=m;i++){
cin>>num2[i];
}
}
int main(){
int res=0;
input();
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(num1[i]==num2[j]){
for(int k=0;k<i;k++){
for(int l=0;l<j;l++){
if(num1[k]==num2[l])
dp[i][j]=max(dp[i][j],dp[k][l]+1);
res=max(res,dp[i][j]);
}
}
}
}
}
cout<<res;
} 边栏推荐
- regular expression
- Control loop of program (while loop)
- Leetcode problem solving - 230 The k-th smallest element in the binary search tree
- flink sql-client 退出,表就会被清空怎么办?
- Station B, dark horse programmer, employee management system, access conflict related (there is an unhandled exception at 0x00007ff633a4c54d (in employee management system.Exe): 0xc0000005: read locat
- Luogu deep foundation part 1 Introduction to language Chapter 7 functions and structures
- Rest reference
- Nacos common configuration
- pivot ROP Emporium
- No matter how hot the metauniverse is, it cannot be separated from data
猜你喜欢

Persistence of Nacos

MySQL - idea connects to MySQL

The post-90s resigned and started a business, saying they would kill cloud database

Notes on MySQL related knowledge points (startup, index)

Asynchronous artifact: implementation principle and usage scenario of completable future

Compilation Principle -- syntax analysis
Implementation principle of inheritance, encapsulation and polymorphism

Après 90 ans, j'ai démissionné pour démarrer une entreprise et j'ai dit que j'allais détruire la base de données Cloud.

常用sql集合
![Intimacy communication -- [repair relationship] - use communication to heal injuries](/img/c2/f10405e3caf570dc6bd124d65b2e93.jpg)
Intimacy communication -- [repair relationship] - use communication to heal injuries
随机推荐
Netfilter ARP log
Preliminary understanding of C program design
Teach you how to install aidlux (1 installation)
JS demo calculate how many days are left in this year
使用dnSpy对无源码EXE或DLL进行反编译并且修改
2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers
Investment analysis and prospect trend prediction report of China's boron nitride industry Ⓨ 2022 ~ 2028
Day 9 HomeWrok-ClassHierarchyAnalysis
The White House held an open source security summit, attended by many technology giants
MySQL——JDBC
Investment planning analysis and prospect prediction report of China's satellite application industry during the 14th five year plan Ⓑ 2022 ~ 2028
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
Implementation principle of inheritance, encapsulation and polymorphism
Capturing and sorting out external articles -- autoresponder, composer, statistics [III]
Remember the experience of automatically jumping to spinach station when the home page was tampered with
Why use pycharm to run the use case successfully but cannot exit?
How PHP drives mongodb
Let me ask you a question. Have you ever used the asynchronous io of Flink SQL to associate dimension tables in MySQL? I set various settings according to the official website
gslb(global server load balance)技術的一點理解
[vulnhub shooting range] impulse: lupinone