当前位置:编程学习 > C/C++ >>

hdu 1257 最少拦截系统(DP)

有点水.....测试数据也很水.....


 

 include<stdio.h>  
int dp[100]; 
int main() 
{ 
    int n,num,i,top; 
    while(~scanf("%d",&n)) 
    { 
        dp[1] = 0; 
        top = 0; 
        while(n--) 
        { 
            scanf("%d",&num); 
            for(i = 1 ; i <= top ; i ++) 
              if(num <= dp[i]) 
              { 
                  dp[i] = num; 
                  break; 
              } 
            if(i > top) dp[++top] = num; 
        } 
        printf("%d\n",top); 
    } 
    return 0; 
} 

#include<stdio.h>
int dp[100];
int main()
{
 int n,num,i,top;
 while(~scanf("%d",&n))
 {
     dp[1] = 0;
     top = 0;
     while(n--)
     {
         scanf("%d",&num);
         for(i = 1 ; i <= top ; i ++)
           if(num <= dp[i])
           {
               dp[i] = num;
               break;
           }
         if(i > top) dp[++top] = num;
     }
     printf("%d\n",top);
 }
 return 0;
}



 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,