当前位置:网站首页>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;
}
边栏推荐
- Kunlun Taike rushes to the scientific innovation board: the annual revenue is 130million, and it plans to raise 500million. CETC Taiji holds 40% of the shares
- 魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
- 03_Solr之dataimport
- 04_solr7.3之solrJ7.3的使用
- 基于伯努利原理的速度监测芯片可用于天然气管道泄露检测
- 做自媒体视频二次剪辑,怎样剪辑不算侵权
- Assembly language
- ASP. Net large takeout ordering system source code (PC version + mobile version + merchant version)
- freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向
- How does redis implement multiple zones?
猜你喜欢
CYCA少儿形体礼仪 宁波市培训成果考核圆满落幕
The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
TiFlash 源码解读(四) | TiFlash DDL 模块设计及实现分析
Share 20 strange JS expressions and see how many correct answers you can get
Countermeasures of enterprise supply chain management system in UCA Era
What is the future development trend of neural network Internet of things
Loop invariant
日化用品行业智能供应链协同系统解决方案:数智化SCM供应链,为企业转型“加速度”
魅族新任董事长沈子瑜:创始人黄章先生将作为魅族科技产品战略顾问
【学习笔记】阶段测试1
随机推荐
怎么叫一手一机的功能方式
Catch all asynchronous artifact completable future
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
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
Guofu hydrogen energy rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, and 360million yuan of accounts receivable exceed the revenue
美国费城发生“安全事故” 2名警察遭枪杀
微服务项目部署后,无法访问静态资源,无法访问到上传到upload中的文件,解决办法
Sharing the 12 most commonly used regular expressions can solve most of your problems
展现强大。这样手机就不会难前进
Countermeasures of enterprise supply chain management system in UCA Era
WebRTC的学习(二)
3W principle [easy to understand]
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)
2022年国内正规的期货公司平台有哪些啊?方正中期怎么样?安全可靠吗?
How to protect user privacy without password authentication?
非技术部门,如何参与 DevOps?
How to make a second clip of our media video without infringement
TiFlash 面向编译器的自动向量化加速
R language ggplot2 visual bar graph: visualize the bar graph through the two-color gradient color theme, and add label text for each bar (geom_text function)
Detailed explanation of SSH password free login