当前位置:网站首页>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;
}
边栏推荐
- How does redis implement multiple zones?
- R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the coef function to obtain the log odds ratio corresponding to eac
- R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)、使用shadow_mark函数为动画添加静态散点图作为动画背景
- How to protect user privacy without password authentication?
- What category does the Internet of things application technology major belong to
- How to make a second clip of our media video without infringement
- The simplest way to open more functions without certificates
- R语言使用MASS包的polr函数构建有序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
- Discussion on memset assignment
- 网上电子元器件采购商城:打破采购环节信息不对称难题,赋能企业高效协同管理
猜你喜欢
快消品行业SaaS多租户解决方案,构建全产业链数字化营销竞争力
How to protect user privacy without password authentication?
SaaS multi tenant solution for FMCG industry to build digital marketing competitiveness of the whole industry chain
周大福践行「百周年承诺」,真诚服务推动绿色环保
Scenario based technology architecture process based on tidb - Theory
Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection
How to introduce devsecops into enterprises?
How can non-technical departments participate in Devops?
Intelligent supply chain collaboration system solution for daily chemical products industry: digital intelligent SCM supply chain, which is the "acceleration" of enterprise transformation
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
随机推荐
R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)、使用shadow_mark函数为动画添加静态散点图作为动画背景
分享 12 个最常用的正则表达式,能解决你大部分问题
Thymeleaf th:with use of local variables
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
Use the word "new" to attract curious people
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 2)
SaaS multi tenant solution for FMCG industry to build digital marketing competitiveness of the whole industry chain
03_Solr之dataimport
Current situation, trend and view of neural network Internet of things in the future
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
Google eventbus usage details
最长公共子序列 - 动态规划
After the microservice project is deployed, static resources and files uploaded to upload cannot be accessed. Solution
美国费城发生“安全事故” 2名警察遭枪杀
网上电子元器件采购商城:打破采购环节信息不对称难题,赋能企业高效协同管理
3W原则[通俗易懂]
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
mysql 自定义函数 身份证号转年龄(支持15/18位身份证)
TDengine 社区问题双周精选 | 第三期
【学习笔记】阶段测试1