当前位置:网站首页>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;
}
边栏推荐
- 为什么我认识的机械工程师都抱怨工资低?
- Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder
- Thymeleaf th:classappend attribute append th:styleappend style append th:data- custom attribute
- 分享 12 个最常用的正则表达式,能解决你大部分问题
- R语言使用原生包(基础导入包、graphics)中的boxplot函数可视化箱图(box plot)
- How to protect user privacy without password authentication?
- 世界环境日 | 周大福用心服务推动减碳环保
- 魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
- WebRTC的学习(二)
- How to introduce devsecops into enterprises?
猜你喜欢
Scenario based technology architecture process based on tidb - Theory
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】
Principle and performance analysis of lepton lossless compression
How can non-technical departments participate in Devops?
世界环境日 | 周大福用心服务推动减碳环保
TiCDC 6.0原理之Sorter演进
Introduction, installation, introduction and detailed introduction to postman!
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
Postman简介、安装、入门使用方法详细攻略!
随机推荐
如何将 DevSecOps 引入企业?
家用电器行业商业供应链协同平台解决方案:供应链系统管理精益化,助推企业智造升级
Why do mechanical engineers I know complain about low wages?
C语言中限定符的作用
Catch all asynchronous artifact completable future
Google eventbus usage details
为什么我认识的机械工程师都抱怨工资低?
[learning notes] connectivity and circuit of graph
Online electronic component purchasing Mall: break the problem of information asymmetry in the purchasing process, and enable enterprises to effectively coordinate management
LeetCode_ 3 (longest substring without repeated characters)
Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million
直播预告|如何借助自动化工具落地DevOps(文末福利)
Loop invariant
R language ggplot2 visualization: gganimate package is based on Transition_ The time function creates dynamic scatter animation (GIF) and uses shadow_ Mark function adds static scatter diagram as anim
TiFlash 源码解读(四) | TiFlash DDL 模块设计及实现分析
快消品行业SaaS多租户解决方案,构建全产业链数字化营销竞争力
How to make a second clip of our media video without infringement
怎么叫一手一机的功能方式
Don't be unconvinced. Mobile phone function upgrade is strong
软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】