当前位置:网站首页>[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;
} 边栏推荐
- MySQL——索引
- What is the difference between res.send() and res.end() in the node express framework
- 大神们,我想发两个广播流1 从mysql加载基础数据,广播出去2 从kafka加载基础数据的变更
- China's coal industry investment strategic planning future production and marketing demand forecast report Ⓘ 2022 ~ 2028
- Are the top ten securities companies safe to open accounts and register? Is there any risk?
- Luogu deep foundation part 1 Introduction to language Chapter 7 functions and structures
- 2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers
- Asynchronous artifact: implementation principle and usage scenario of completable future
- What if the Flink SQL client exits and the table is emptied?
- 2022-02-15 Daily: 2022 AAAI fellow release
猜你喜欢

UC Berkeley proposes a multitask framework slip

No matter how hot the metauniverse is, it cannot be separated from data

MySQL——索引

使用dnSpy对无源码EXE或DLL进行反编译并且修改

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

MySQL——数据库备份

QFileDialog

Covariance

Control loop of program (while loop)

Morning flowers and evening flowers
随机推荐
How to store null value on the disk of yyds dry inventory?
Cognitive fallacy: Wittgenstein's ruler
17 websites for practicing automated testing. I'm sure you'll like them
Redis concludes that the second pipeline publishes / subscribes to bloom filter redis as a database and caches RDB AOF redis configuration files
油猴插件
MySQL——索引
Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
Report on the development strategy of China's engineering bidding agency and suggestions for the 14th five year plan Ⓙ 2022 ~ 2028
大神们,我想发两个广播流1 从mysql加载基础数据,广播出去2 从kafka加载基础数据的变更
Sed、Awk
国泰君安证券开户是安全可靠的么?怎么开国泰君安证券账户
Collections SQL communes
JS notes (III)
DR-AP40X9-A-Qualcomm-IPQ-4019-IPQ-4029-5G-4G-LTE-aluminum-body-dual-band-wifi-router-2.4GHZ-5GHz-QSD
Goodbye 2021, how do programmers go to the top of the disdain chain?
Covariance
Farmersworld farmers world, no faith, how to talk about success?
抓包整理外篇——————autoResponder、composer 、statistics [ 三]
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
Advanced technology management - how to examine candidates in the interview and increase the entry probability