题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257
/**
定义一个数组set[3000] 初始化为0,0代表未启用;
从拦截第一发导弹开始,每次选择最优解,从数组第一个元素开始遍历,找到大于本次拦截导弹高度的高度最小的系统,如果没有新开一套系统;运行过程中数组set里存的已启用的系统高度递增。
*/
#include <stdio.h>
#include <string.h>
/**
* 考点:贪心算法
*/
int set[30000];
int main() {
int num;
int setNum;
while (scanf("%d", &num) != EOF) {
setNum = 0;
memset(set, 0, sizeof(set)); //初始化为0
while (num--) {
int h;
scanf("%d", &h);
int index = 0;
while (1) {
if (set[index] >= h) {
set[index] = h;
break;
} else if (set[index] == 0) {
set[index] = h;
setNum++; //多一套系统
break;
}
index++;
}
}
printf("%d\n", setNum);
}
}