ZOJ 2136 Longest Ordered Subsequence

 1 #include<time.h>
 2 #include <cstdio>  
 3 #include <iostream>  
 4 #include<algorithm>
 5 #include<math.h> 
 6 #include <string.h>  
 7 #include<vector> 
 8 #include<queue>
 9 using namespace std;
10 
11 int d[100005],a[100005];
12 int len,i,k,n,m;
13 
14 int binary(int t)
15 {
16     int low,high,mid;
17     low=0;
18     high=len;
19     while(low<high)
20     {
       //mid=low+(high-low)*(num-p[low])/(p[high]-p[low]);//插值排序
21 mid=(low+high)/2; 22 if(d[mid]<=t) 23 low=mid+1; 24 else 25 high=mid; 26 } 27 return low; 28 } 29 30 int main() 31 { 32 int cas; 33 cin>>cas; 34 while(cas--) 35 { 36 cin>>n; 37 for(i=1;i<=n;i++) 38 cin>>a[i]; 39 len=0; 40 d[0]=-99999; 41 for(i=1;i<=n;i++) 42 { 43 if(a[i]>d[len]) 44 { 45 len++; 46 d[len]=a[i]; 47 //cout<<d[len]<<" "; 48 } 49 else 50 { 51 k=binary(a[i]); 52 d[k]=a[i]; 53 } 54 } 55 cout<<len<<endl; 56 if(cas) //这里是个坑 57 cout<<endl; 58 } 59 return 0; 60 }

 

转载于:https://www.cnblogs.com/pter/p/5410040.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值