最少拦截系统

HDOJ-1257

  • 我做这题的思路就是采用暴力或者贪心。也就是每次循环选出从第一个未被选择的元素开始,依次把后面可以选择的元素作为一个系统。最后统计可以有多少个系统。
  • 还有人的思路就是利用动态规划的思路,求解最长上升子序列,也就是反着题意来求。因为在这个最长上升子序列中,所有的元素不可能在同一个拦截系统中,所以子序列的长度就是最后的答案,也就是拦截系统的个数
  • https://blog.csdn.net/qq_29963431/article/details/49081409
  • 还有博客介绍的方法相对我的解题思路来说上了一个台阶,使用了优化,每次记录一个拦截系统中以后可以拦截的最高度。https://blog.csdn.net/hurmishine/article/details/52926957
//最长上升子序列的变形
#include<bits/stdc++.h>
using namespace std;
const int INF=0X3F3F3F3F;
const int maxn=1e6;
int n;
int height[maxn];
bool vis[maxn];
int main(){
while(cin>>n){
for(int i=1;i<=n;i++){
cin>>height[i];
}
int ans=0;
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++){
bool flag=false;
int pre=INF;
for(int j=1;j<=n;j++){
if(!vis[j]&&pre>height[j]){
flag=true;
vis[j]=true;
pre=height[j];
}
}
if(flag)
ans++;
}
cout<<ans<<endl;
}
return 0;
}

最新文章

  1. 图文介绍如何在Eclipse统计代码行数
  2. Python的第一天
  3. 大毕设-MATLAB-FFT实现
  4. R in a nutshell(连载)
  5. 基于HTML5的WebGL呈现A星算法的3D可视化
  6. ACM/ICPC 之 拓扑排序+DFS(POJ1128(ZOJ1083)-POJ1270)
  7. 解决python &quot;Non-ASCII character&quot;错误
  8. JS 动画基础
  9. html5 input type=search
  10. Linux目录结构及文件基础操作
  11. zabbix_agent-linux下的安装
  12. jQuery / zepto ajax 全局默认设置
  13. 51nod 1536不一样的猜数游戏 思路:O(n)素数筛选法。同Codeforces 576A Vasya and Petya&#39;s Game。
  14. 《java.util.concurrent 包源码阅读》13 线程池系列之ThreadPoolExecutor 第三部分
  15. 生成式模型之 GAN
  16. 使用 wordcloud 构建词云图
  17. SpringBoot学习笔记1
  18. Coursera, Deep Learning 1, Neural Networks and Deep Learning - week2, Neural Networks Basics
  19. javanio1----传统io
  20. mysql库、表、索引

热门文章

  1. cmath取整函数
  2. HDU 3537 Daizhenyang&#39;s Coin 翻硬币博弈
  3. Codeforces Round #650 (Div. 3) F1. Flying Sort (Easy Version) (离散化,贪心)
  4. VS2010的单元测试(二)
  5. Linux系统诊断必备技能之三:查看信息系统常用命令
  6. 快速下载 Visual Studio Code
  7. DLL &amp; Dynamic-link library
  8. HTTPS in depth
  9. how to read the system information by using the node cli tool?
  10. Flutter Vignettes