当前位置:网站首页>[dynamic programming] Jisuan Ke: Jumping stake (variant of the longest increasing subsequence)
[dynamic programming] Jisuan Ke: Jumping stake (variant of the longest increasing subsequence)
2022-07-03 21:57:00 【muse_ age】
There is a row in front of you n A stake , The heights of the wooden piles are h1,h2,h3…hn. Garlic can jump to any stake in the first step , The garlic can't jump back at the next step, but can only jump forward , And jump down to the height of a stake No more than Current stake . Mr. garlic hopes to step on as many stakes as possible , Please help garlic calculate , How many stakes can you step on at most .
Input format
Enter an integer in the first line n Represents the number of wooden piles . Second line input n It's an integer h1,h2,h3..hn, Represent the n The height of a stake .(1≤n≤1000,1≤hi≤100000)
Output format
Output an integer , Represents the maximum number of wooden piles that can be stepped on , Occupy a line .
The sample input
6
3 6 4 1 4 2
Sample output
4
The question : Find the length of the longest non increasing subsequence of a group of numbers
dp[i] Said to nums[i] Length of the longest non increasing subsequence at the end
initialization : dp[0]=0
State transition equation :dp[i]=max{dp[j]}+1,if(nums[j]>=nums[i]) 0<=j<i
Code :
#include<iostream>
using namespace std;
int nums[100];
int dp[100];
int n;
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>nums[i];
}
dp[0]=nums[0];
int res=INT_MAX;
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(nums[j]>=nums[i])
dp[i]=max(dp[i],dp[j]+1);
res=max(res,dp[i]);
}
}
cout<<res;
}
边栏推荐
- Service discovery and load balancing mechanism -service
- How PHP gets all method names of objects
- China's TPMS industry demand forecast and future development trend analysis report Ⓐ 2022 ~ 2028
- Sed、Awk
- MySQL——规范数据库设计
- The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
- The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)
- (5) User login - services and processes - History Du touch date stat CP
- Common SQL sets
- treevalue——Master Nested Data Like Tensor
猜你喜欢
Collections SQL communes
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
TiDB 之 TiCDC6.0 初体验
Nacos common configuration
On my first day at work, this API timeout optimization put me down!
Introduction to kubernetes
Common SQL sets
MySQL——数据库备份
Collection | pytoch common loss function disassembly
The post-90s resigned and started a business, saying they would kill cloud database
随机推荐
Global and Chinese market of AC induction motors 2022-2028: Research Report on technology, participants, trends, market size and share
Persistence of Nacos
Dynamic research and future planning analysis report of China's urban water supply industry Ⓝ 2022 ~ 2028
Leetcode problem solving - 235 Nearest common ancestor of binary search tree
Intimacy communication -- [repair relationship] - use communication to heal injuries
Decompile and modify the non source exe or DLL with dnspy
Analysis report on the development trend and Prospect of global and Chinese supercontinuum laser source industry Ⓚ 2022 ~ 2027
Sed、Awk
WFC900M-Network_ Card/Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-900M-high-power-Mini-PCIe-Wi-Fi-Mod
抓包整理外篇——————autoResponder、composer 、statistics [ 三]
内存分析器 (MAT)
UI automation test: selenium+po mode +pytest+allure integration
How PHP adds two numbers
Implementation principle of inheritance, encapsulation and polymorphism
2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
Yiwen teaches you how to choose your own NFT trading market
DOM light switch case
What is the difference between res.send() and res.end() in the node express framework
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
How to install sentinel console