当前位置:网站首页>Niuke: intercepting missiles
Niuke: intercepting missiles
2022-07-05 14:20:00 【lsgoose】
This problem is transformed into the problem of finding the longest increasing subsequence through a mathematical theorem .
First , The first question is obviously to find the longest non decreasing subsequence , The second question is to use a theorem , You can refer to :
Dilworth What is the theorem _litble The blog of -CSDN Blog _dilworth Theorem
Finally, after transforming the problem , The solution is very simple , mathematics yyds, The code is as follows :
#include<bits/stdc++.h>
using namespace std;
// Find the length of the longest non decreasing subsequence
int solve1(vector<int> &height){
int len=height.size();
int res=INT_MIN;
vector<int> dp(len, 1);
for(int i=0;i<len;++i){
for(int j=0;j<i;++j){
if(height[i] <= height[j]){
dp[i]=max(dp[i], dp[j]+1);
}
}
res=max(res, dp[i]);
}
return res;
}
// Find the length of the longest increasing subsequence
int solve2(vector<int> &height){
int len=height.size();
int res=INT_MIN;
vector<int> dp(len, 1);
for(int i=0;i<len;++i){
for(int j=0;j<i;++j){
if(height[i] > height[j]){
dp[i]=max(dp[i], dp[j]+1);
}
}
res=max(res, dp[i]);
}
return res;
}
int main(){
int n;
cin>>n;
vector<int> height(n);
for(int i=0;i<n;++i){
cin>>height[i];
}
int res1=solve1(height);
int res2=solve2(height);
cout<<res1<<endl<<res2<<endl;
return 0;
}
边栏推荐
- Enjoy what you want. Zhichuang future
- The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
- Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
- Countermeasures of enterprise supply chain management system in UCA Era
- R language ggplot2 visual density map: Visual density map by group and custom configuration geom_ The alpha parameter in the density function sets the image transparency (to prevent multiple density c
- Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
- Some ideas about Apache mesos
- Oneconnect listed in Hong Kong: with a market value of HK $6.3 billion, ye Wangchun said that he was honest and trustworthy, and long-term success
- Thymeleaf th:classappend attribute append th:styleappend style append th:data- custom attribute
- The forked VM terminated without saying properly goodbye
猜你喜欢
基于 TiDB 场景式技术架构过程 - 理论篇
Lepton 无损压缩原理及性能分析
freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向
What are the advantages and characteristics of SAS interface
Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder
TDengine 社区问题双周精选 | 第三期
TiCDC 6.0原理之Sorter演进
Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million
Sharing the 12 most commonly used regular expressions can solve most of your problems
Oneconnect listed in Hong Kong: with a market value of HK $6.3 billion, ye Wangchun said that he was honest and trustworthy, and long-term success
随机推荐
R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram, and use the labs parameter to customize the X axis label text (customize X axis labels)
Redis如何实现多可用区?
Thymeleaf th:classappend attribute append th:styleappend style append th:data- custom attribute
【学习笔记】图的连通性与回路
Thymeleaf 常用函数
R语言ggplot2可视化条形图:通过双色渐变配色颜色主题可视化条形图、为每个条形添加标签文本(geom_text函数)
别不服气。手机功能升级就是强
After the microservice project is deployed, static resources and files uploaded to upload cannot be accessed. Solution
The simplest way to open more functions without certificates
PMP考试20天能通过吗?
01. Solr7.3.1 deployment and configuration of jetty under win10 platform
04_solr7.3之solrJ7.3的使用
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 2)
Share 20 strange JS expressions and see how many correct answers you can get
Tiflash compiler oriented automatic vectorization acceleration
动态规划
Thymeleaf th:classappend属性追加 th:styleappend样式追加 th:data-自定义属性
Interpretation of tiflash source code (IV) | design and implementation analysis of tiflash DDL module
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
魅族新任董事长沈子瑜:创始人黄章先生将作为魅族科技产品战略顾问