当前位置:网站首页>[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;
}
边栏推荐
- (5) User login - services and processes - History Du touch date stat CP
- 2022-2-14 acwing1027 grid access
- Leetcode problem solving - 230 The k-th smallest element in the binary search tree
- Investment analysis and prospect trend prediction report of China's boron nitride industry Ⓨ 2022 ~ 2028
- What if the Flink SQL client exits and the table is emptied?
- Global and Chinese market of wireless hard disk 2022-2028: Research Report on technology, participants, trends, market size and share
- 请教大家一个问题,用人用过flink sql的异步io关联MySQL中的维表吗?我按照官网设置了各种
- UC Berkeley proposes a multitask framework slip
- Investment planning analysis and prospect prediction report of China's satellite application industry during the 14th five year plan Ⓑ 2022 ~ 2028
- Global and Chinese market of recycled yarn 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
Covariance
Day 9 HomeWrok-ClassHierarchyAnalysis
No more! Technical team members resign collectively
Mysql - - Index
常用sql集合
Asynchronous artifact: implementation principle and usage scenario of completable future
What should the future of the Internet be like when Silicon Valley employees flee the big factory and rush to Web3| Footprint Analytics
Correlation
Compréhension de la technologie gslb (Global Server load balance)
gslb(global server load balance)技术的一点理解
随机推荐
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
使用dnSpy對無源碼EXE或DLL進行反編譯並且修改
UI automation test: selenium+po mode +pytest+allure integration
Is it OK for fresh students to change careers to do software testing? The senior answered with his own experience
Common SQL sets
Cognitive fallacy: what is Fredkin's paradox
No more! Technical team members resign collectively
90 後,辭職創業,說要卷死雲數據庫
Sed、Awk
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Minio deployment
MySQL——JDBC
Base ring tree Cartesian tree
treevalue——Master Nested Data Like Tensor
Covariance
How PHP gets all method names of objects
Décompiler et modifier un exe ou une DLL non source en utilisant dnspy
Memory analyzer (MAT)
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
(5) User login - services and processes - History Du touch date stat CP