LIS Nlogn Template http://acm.hdu.edu.cn/showproblem.php?pid=1950
#include <iostream>#include<stdio.h>#include<algorithm>#include<string>#include<math.h>#include<stdlib.h>#defineMAXN 40000+10using namespacestd;intA[maxn],d[maxn],len;intBsinti) { intL,r,mid; L=0, r=Len; while(l<S) {Mid= (l+r)/2; if(D[mid]>=a[i]) r=mid; ElseL=mid+1; } returnl;}intMain () {intT,n; scanf ("%d",&T); while(t--) {scanf ("%d",&N); for(intI=1; i<=n;i++) scanf ("%d",&A[i]); d[1]=a[1]; Len=1; for(intI=2; i<=n;i++){ if(a[i]>D[len]) d[++len]=A[i]; Else{ intPos=lower_bound (D,d+len,a[i])-D; D[pos]=a[i];//find >=a[i] and update}} printf ("%d\n", Len); } return 0;}
LIS n^2 Template http://poj.org/problem?id=2533
#include <iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<math.h>#defineINF 0x3f3f3f3f#defineMAXN 10000+10using namespacestd;intA[MAXN],N,DP[MAXN];intMain () { while(cin>>N) { intlen=-1; for(intI=1; i<=n;i++) scanf ("%d",&A[i]); dp[0]=-INF; for(intI=1; i<=n;i++) {Dp[i]=1; for(intj=0; j<i;j++){ if(A[i]>a[j])//when conditions are metDp[i]=max (dp[i],dp[j]+1); if(Dp[i]>len) len=Dp[i]; }} printf ("%d\n", Len); } return 0;}
LIS N^2&nlogn Templates