怒刷DP之 HDU 1257

最少拦截系统
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Appoint description: 

Description

某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统. 
 

Input

输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔) 
 

Output

对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统. 
 

Sample Input

8 389 207 155 300 299 170 158 65
 

Sample Output

2
 
 
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <string>
 4 #include <queue>
 5 #include <vector>
 6 #include <map>
 7 #include <algorithm>
 8 #include <cstring>
 9 #include <cctype>
10 #include <cstdlib>
11 #include <cmath>
12 #include <ctime>
13 #include <climits>
14 using    namespace    std;
15 
16 const    int    INF = 0x7fffffff;
17 vector<int>    DP;
18 
19 int    main(void)
20 {
21     int    n,box;
22 
23     while(scanf("%d",&n) != EOF)
24     {
25         DP.clear();
26         while(n --)
27         {
28             scanf("%d",&box);
29             int    loc = 0;
30             int    min = INF;
31             for(int i = 0;i < DP.size();i ++)
32                 if(DP[i] - box >= 0 && DP[i] - box < min)
33                 {
34                     min = DP[i] - box;
35                     loc = i;
36                 }
37             if(min == INF)
38                 DP.push_back(box);
39             else
40                 DP[loc] = box;
41         }
42         printf("%d\n",DP.size());
43 
44     }
45 
46     return    0;
47 }

 

 
posted @ 2015-09-07 17:21  Decouple  阅读(187)  评论(0编辑  收藏  举报