当前位置:网站首页>[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;
}
边栏推荐
- Market layout planning and latest dynamic analysis report of China's smart public security industry Ⓕ 2022 ~ 2028
- DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
- C程序设计的初步认识
- Imitation Netease cloud music applet
- Go language slice interview real question 7 consecutive questions
- Remember the experience of automatically jumping to spinach station when the home page was tampered with
- How to store null value on the disk of yyds dry inventory?
- 使用dnSpy對無源碼EXE或DLL進行反編譯並且修改
- Idea shortcut word operation
- Report on the development strategy of China's engineering bidding agency and suggestions for the 14th five year plan Ⓙ 2022 ~ 2028
猜你喜欢
(5) User login - services and processes - History Du touch date stat CP
UI automation test: selenium+po mode +pytest+allure integration
使用dnSpy對無源碼EXE或DLL進行反編譯並且修改
A little understanding of GSLB (global server load balance) technology
Monkey/ auto traverse test, integrate screen recording requirements
Implementation principle of inheritance, encapsulation and polymorphism
Tidb's initial experience of ticdc6.0
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
How PHP drives mongodb
[secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]
随机推荐
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
How PHP gets all method names of objects
Getting started with postman -- environment variables and global variables
Why use pycharm to run the use case successfully but cannot exit?
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
4. Data splitting of Flink real-time project
请教大家一个问题,用人用过flink sql的异步io关联MySQL中的维表吗?我按照官网设置了各种
WFC900M-Network_ Card/Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-900M-high-power-Mini-PCIe-Wi-Fi-Mod
Implementation principle of inheritance, encapsulation and polymorphism
Tidb's initial experience of ticdc6.0
[vulnhub shooting range] impulse: lupinone
JS Demo calcule combien de jours il reste de l'année
TiDB 之 TiCDC6.0 初体验
The latest analysis of R1 quick opening pressure vessel operation in 2022 and the examination question bank of R1 quick opening pressure vessel operation
Correlation
Pengcheng cup Web_ WP
Day 9 HomeWrok-ClassHierarchyAnalysis
How to store null value on the disk of yyds dry inventory?
js demo 计算本年度还剩下多少天
Mysql - - Index