HDU 1257 最少拦截系统

code:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=30001;
int a[maxn];
int dp[maxn];
int n;
void judge()
{
   while(~scanf("%d",&n))//scanf("%d",&n);
   {
       memset(dp,0,sizeof(dp));
   for(int i=0;i<n;++i){
       scanf("%d",a+i);
       dp[i]=a[i];}
   int num=1;
   int side=1;
   for(int i=1;i<n;++i)
   {
       int flag=0;
        for(int j=0;j<side;++j)
        {
          if(dp[j]>a[i])
          {
             dp[j]=a[i];
             flag=1;
             break;
          }
        }
        if(!flag)
            dp[side++]=a[i];
   }
   printf("%d\n",side);
}
   return ;
}
int main()
{
    judge();
    return 0;
}


  点击打开链接

你可能感兴趣的:(HDU 1257 最少拦截系统)