#include<stdio.h>
#include<stdlib.h>
/*
飞弹能够沿固定方向摧毁高度递减的目标。
现在已知一直线上从左到右各个目标的高度。需要你求出飞弹最多能够摧毁多少目标。
飞弹自最左端发射,起始高度任意,从左至右摧毁目标。
*/
int main()
{
int target_height[1002] = { 0 };
int destory[1002];
int NUM = 0;
int max = -10;
scanf("%d", &NUM);
for (int i = 0; i < NUM; i++)//输入目标参数 { scanf("%d", &target_height[i]); destory[i] = 1; //scanf("% *[^ \n] % *c"); } for (int i = NUM-1; i >=0; i--)//暴力测试
{
max = 0;
for (int k = i+1; k < NUM; k++)
if (target_height[k] < target_height[i] && max < destory[k]) //表明某一目标后头能打多少个
max = destory[k];
destory[i] += max; //当前的一个加上能打的多少个就是总数
}
for (int i = 0; i < NUM; i++)
{
if (max < destory[i])
max = destory[i];
}
printf("%d", max);
return 0;
}
《NOJ1161 飞弹》有1个想法