当前位置:网站首页>[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;
} 边栏推荐
- Introduction to kubernetes
- Under the double reduction policy, research travel may become a big winner
- DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
- Luogu deep foundation part 1 Introduction to language Chapter 7 functions and structures
- Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
- How PHP drives mongodb
- Mysql - - Index
- MySQL - index
- Dahua series books
- 国泰君安证券开户是安全可靠的么?怎么开国泰君安证券账户
猜你喜欢

Mysql - - Index

Persistence of Nacos

仿网易云音乐小程序

Nacos common configuration

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

MySQL - idea connects to MySQL

treevalue——Master Nested Data Like Tensor

Why use pycharm to run the use case successfully but cannot exit?

Experience summary of database storage selection

Selenium has three waiting methods (forced waiting, implicit waiting, and display waiting)
随机推荐
Minio deployment
The 14th five year plan and investment feasibility study report of China's industry university research cooperation Ⓧ 2022 ~ 2028
Under the double reduction policy, research travel may become a big winner
常用sql集合
Morning flowers and evening flowers
使用dnSpy对无源码EXE或DLL进行反编译并且修改
Analysis report on the development prospect and investment strategy of global and Chinese modular automation systems Ⓟ 2022 ~ 2027
treevalue——Master Nested Data Like Tensor
Is it OK for fresh students to change careers to do software testing? The senior answered with his own experience
treevalue——Master Nested Data Like Tensor
Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
Rest参考
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
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
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
Experience summary of database storage selection
Global and Chinese market of telematics boxes 2022-2028: Research Report on technology, participants, trends, market size and share
What is the content of the securities practice examination?
Service discovery and load balancing mechanism -service
MySQL——SQL注入问题