当前位置:网站首页>[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——规范数据库设计
- Leetcode problem solving - 235 Nearest common ancestor of binary search tree
- 常用sql集合
- Service discovery and load balancing mechanism -service
- Getting started with DOM
- DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
- 使用dnSpy對無源碼EXE或DLL進行反編譯並且修改
- Global and Chinese market of AC induction motors 2022-2028: Research Report on technology, participants, trends, market size and share
- Functions and differences between static and Const
- 内存分析器 (MAT)
猜你喜欢

Yiwen teaches you how to choose your own NFT trading market

Minio deployment

MySQL——JDBC

常用sql集合

MySQL——索引

Day 9 HomeWrok-ClassHierarchyAnalysis

Functions and differences between static and Const

Imitation Netease cloud music applet
Implementation principle of inheritance, encapsulation and polymorphism

2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
随机推荐
2022-02-15 Daily: 2022 AAAI fellow release
请教大家一个问题,用人用过flink sql的异步io关联MySQL中的维表吗?我按照官网设置了各种
Intimacy communication -- [repair relationship] - use communication to heal injuries
Getting started with postman -- built-in dynamic parameters, custom parameters and assertions
Analysis report on the development trend and Prospect of global and Chinese supercontinuum laser source industry Ⓚ 2022 ~ 2027
China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
On my first day at work, this API timeout optimization put me down!
Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
Quickly distinguish slices and arrays
Remember the experience of automatically jumping to spinach station when the home page was tampered with
Goodbye 2021, how do programmers go to the top of the disdain chain?
Rest参考
常用sql集合
What is the difference between res.send() and res.end() in the node express framework
Global and Chinese market of gallic acid 2022-2028: Research Report on technology, participants, trends, market size and share
Idea shortcut word operation
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.
MySQL - idea connects to MySQL
Investment analysis and prospect trend prediction report of China's boron nitride industry Ⓨ 2022 ~ 2028
Asynchronous artifact: implementation principle and usage scenario of completable future