标签:
#include <iostream> using namespace std; void FindPlan(int* data,int num) { int* count = new int[num]; for(int i = 0;i < num; i++) count[i] = 0; int maxi; /*if(num>=2&&data[num-1]<=data[num-2]) count[num-1] = 1;*/ count[num-1] = 1; //若击落最后一个导弹则只能击中一个 for(i = num-2;i >= 0; i--) //从倒数第二枚导弹开始计数,若从第i枚导弹并开始打击(包含第i枚)能打击多少枚导弹 { maxi = 0; for(int j = i+1;j < num; j++) if(data[j]<=data[i]&&count[j]>maxi) maxi = count[j]; count[i] = maxi+1; /*cout<<i<<endl; for(int k = 0;k < num; k++) cout<<count[k]<<" "; cout<<endl;*/ } int max = 0; /*for(i = 0;i < num; i++) cout<<count[i]<<" "; cout<<endl;*/ for(i = 0;i < num; i++) if(count[i]>max) max = count[i]; cout<<max<<endl; free(count); } int main() { int num; int *data; cin>>num; while(num!=0) { data = new int[num]; for(int i = 0;i < num; i++) cin>>data[i]; FindPlan(data,num); free(data); cin>>num; } return 0; }
标签:
原文地址:http://www.cnblogs.com/lxk2010012997/p/4417968.html