Time limit:1 Sec Memory limit:128 MB
submit:1325 solved:722
Description given an n-length sequence AI, the longest length of the AI's subsequence bi is satisfied with bi&bi-1!=0 (2<=i<=len). Input file total 2 rows. The first line includes an integer n. The second line includes n integers, and the first integer represents AI. Output file has a single row. Includes an integer that represents the longest length of the subsequence bi. Sample Input3
1 2 3Sample Output2HINT
N<=100000,ai<=2*10^9
Source
by Oxer
Just started to be frightened, thought, originally is a similar LIS DP.
F[J] represents the sequence length of the last number of sequences in binary J bits 1. Specific transfer See Code
1 /*by Silvern*/2#include <iostream>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <algorithm>7 #defineLL Long Long8 using namespacestd;9 Const intmxn=100010;Ten intRead () { One intx=0, f=1;CharCh=GetChar (); A while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx*F; the } - intN; - intf[ +],a[mxn],b[ +]; - intMain () { +n=read (); - inti,j; + for(i=1; i<=n;i++) Aa[i]=read (); atb[0]=1; - for(j=1; j<= -; j + +) -B[j]= (b[j-1]<<1); - for(i=1; i<=n;i++){ - inttmp=0; - for(j=0;j< to; j + +) in if(A[i]&b[j]) Tmp=max (tmp,f[j]+1); - for(j=0;j< to; j + +) to if(A[i]&b[j]) f[j]=Max (f[j],tmp); + } - intans=0; the for(j=0;j< to; j + +) ans=Max (ans,f[j]); *printf"%d\n", ans); $ return 0;Panax Notoginseng}
Bzoj4300 great problem