设为首页 加入收藏

TOP

HDU 1950 Bridging signals (DP)
2015-07-20 17:33:55 来源: 作者: 【 】 浏览:1
Tags:HDU 1950 Bridging signals

题目地址:HDU 1950

这题是求最长上升序列,但是普通的最长上升序列求法时间复杂度是O(n*n),显然会超时。于是便学了一种O(n*logn)的方法。也很好理解。感觉还用到了一点贪心的思想。

具体的见这篇博客吧,写的很通俗易懂。传送门

代码如下:

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #include 
           #include 
           
             #include 
            
              using namespace std; #define LL long long int a[50000], b[50000], len; int bin_seach(int x) { int low=1, high=len, mid, ans; while(low<=high) { mid=low+high>>1; if(b[mid]>=x) {high=mid-1;ans=mid;} else low=mid+1; } return ans; } int main() { int t, n, i, pos; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0;i
             
              b[len]) { b[++len]=a[i]; } else { pos=bin_seach(a[i]); b[pos]=a[i]; } } printf("%d\n",len); } return 0; } 
             
            
           
         
        
       
      
     
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇BZOJ 2561 最小生成树 网络流 最.. 下一篇Hdu 3341 Lost's revenge (ac..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)