HDU 1257 最少拦截系统
来源:互联网 发布:mysql 自带记录行号 编辑:程序博客网 时间:2024/05/22 22:40
Problem Description
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
Input
输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)
Output
对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
总结:
这道题一开始我使用的贪心策略是每次击落尽可能多的导弹,但是这个策略的正确性还是有问题:(,其实我们只需要统计不下降的序列就可以,因为这些元素一定要用一个新的拦截系统去拦截,这个关系并不是显而易见的,通过画图什么的我们可以发现,最长不下降子序列的元素一定要新的拦截系统去拦截。
2////// main.cpp//// 导弹拦截系统//////// Created by 张嘉韬 on 16/8/12.//// Copyright © 2016年 张嘉韬. All rights reserved.////////#include <iostream>//#include <cstring>//#include <cstdio>//using namespace std;//const int maxn=1000000;//int f[maxn][3],a[maxn];//int main(int argc, const char * argv[]) {// freopen("/Users/zhangjiatao/Documents/暑期训练/input.txt","r",stdin);// int n;// while(scanf("%d",&n)!=EOF)// {// int r=0,counter=n;// memset(f,0,sizeof(f));// for(int i=1;i<=n;i++) scanf("%d",&a[i]);// while(counter!=0)// {// r++;// int round=0;// for(int i=1;i<=n;i++)// {// if(f[i][2]==1) continue;// int maximum=0,maxp=i;// for(int j=1;j<i;j++)// {// if(a[i]<a[j]&&f[j][2]==0)// {// if(f[j][0]>maximum) {maximum=f[j][0]; maxp=j;}// }// }// f[i][0]=maximum+1;// f[i][1]=maxp;// if(f[i][0]>f[round][0]) round=i;// }//// for(int i=1;i<=n;i++)//// {//// cout<<f[i][0]<<" ";//// }//// cout<<endl;//// cout<<f[round][0]<<" ";//// cout<<endl;// counter-=f[round][0];// if(counter==0) {printf("%d\n",r);break;}// int temp=round;// while(1)// {// //cout<<temp<<" ";// if(f[temp][1]==temp) {f[temp][2]=1;break;}// f[temp][2]=1;// temp=f[temp][1];// }// //cout<<endl;// }// // }// return 0;//}//// 1 2 3 2 3 4 5 6////8 389 207 155 300 299 170 158 65//// 1 2 3 4 5 6 7 8//// 389 207 170 158 65//// 155 300 299//////#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int maxn=1000000+10;int a[maxn],f[maxn];int main(){ int n; while(scanf("%d",&n)!=EOF) { int r=0; memset(f,0,sizeof(f)); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { int maximum=0; for(int j=1;j<=n;j++) { if(a[i]>=a[j]) { if(f[j]>maximum) maximum=f[j]; } } f[i]=maximum+1; if(f[i]>r) r=f[i]; } printf("%d\n",r); } return 0;}
0 0
- hdu 1257 最少拦截系统
- 最少拦截系统 hdu 1257
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- HDU 1257 最少拦截系统
- hdu 1257 最少拦截系统
- hdu 1257 最少拦截系统
- Android各种蓝牙设备的UUID
- 20160812Object-c关于内存管理一
- 使用spring-data-redis进行对redis的操作,封装的一些操作方法
- 25.html标签居然可以写事件
- SQL Server连接Oracle详细步骤
- HDU 1257 最少拦截系统
- SVN服务器搭建和使用(二)
- Bluetooth MTU
- Python Tricks(十九)—— switch 的实现
- GSON方式生成和解析json数据
- Unity Mecanim动画的实现(六):动画事件,实现动画过程中的事件处理
- Runnabel 与Thread
- Hibernate 参数设置一览表
- 指针和引用的区别