HDOJ-1257(贪心/动态规划)
2024-08-30 10:58:19
最少拦截系统
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;
}
最新文章
- 图文介绍如何在Eclipse统计代码行数
- Python的第一天
- 大毕设-MATLAB-FFT实现
- R in a nutshell(连载)
- 基于HTML5的WebGL呈现A星算法的3D可视化
- ACM/ICPC 之 拓扑排序+DFS(POJ1128(ZOJ1083)-POJ1270)
- 解决python ";Non-ASCII character";错误
- JS 动画基础
- html5 input type=search
- Linux目录结构及文件基础操作
- zabbix_agent-linux下的安装
- jQuery / zepto ajax 全局默认设置
- 51nod 1536不一样的猜数游戏 思路:O(n)素数筛选法。同Codeforces 576A Vasya and Petya&#39;s Game。
- 《java.util.concurrent 包源码阅读》13 线程池系列之ThreadPoolExecutor 第三部分
- 生成式模型之 GAN
- 使用 wordcloud 构建词云图
- SpringBoot学习笔记1
- Coursera, Deep Learning 1, Neural Networks and Deep Learning - week2, Neural Networks Basics
- javanio1----传统io
- mysql库、表、索引
热门文章
- cmath取整函数
- HDU 3537 Daizhenyang&#39;s Coin 翻硬币博弈
- Codeforces Round #650 (Div. 3) F1. Flying Sort (Easy Version) (离散化,贪心)
- VS2010的单元测试(二)
- Linux系统诊断必备技能之三:查看信息系统常用命令
- 快速下载 Visual Studio Code
- DLL &; Dynamic-link library
- HTTPS in depth
- how to read the system information by using the node cli tool?
- Flutter Vignettes