问题:最长上升子序列
import java.util.*; public class Main{ static Scanner sc=new Scanner(System.in); static int N=100010; //写法一: static int a[]=new int[N],q[]=new int[N]; //写法二: // static int[] a=new int[N],q=new int[N]; public static void main(String args[]){ int n=sc.nextInt(); for(int i=0;i<n;i++) a[i]=sc.nextInt(); int len=0; for(int i=0;i<n;i++){ int l=0,r=len; while(l<r){//排队,最适合的在最前,实时更新 int mid=l+r+1>>1; if(q[mid]<a[i]) l=mid; else r=mid-1; } len=Math.max(len,r+1); q[r+1]=a[i]; } System.out.println(len); } }