贪心, 从前面往后读取,对于每一个高度,都要用之前一个系统最接近的高度来消灭,这样才最省。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <cmath>
#include <iomanip>
#include <cmath>
typedef long long LL;
typedef unsigned long long LLU;
const double PI=acos(-1.0);
using namespace std;
#define MAXN 100000+10
#define INF 1 << 30
int main (){
int n;
while(scanf("%d",&n) != EOF){
int a[MAXN] = {0};
for(int i = 1; i <= n; i++)
scanf("%d",&a[i]);
int maxh[MAXN];
int ans = 1;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= ans; j++){
if(a[i] <= maxh[j]){
maxh[j] = a[i];
break;
}
if(a[i] > maxh[j] && j == ans){
maxh[++ans] = a[i];
break;
}
}
}
printf("%d\n",ans-1);
}
return 0;
}