Question: https://www.lydsy.com/JudgeOnline/problem.php? Id = 4300
Consider which J can be transferred from DP [I], that is, a [J] & A [I]! 0, that is, there is at least one common 1. Therefore, the value of DP [] in a [] of 1 is recorded on 30 bits, it will be transferred.
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=1e5,M=35;int n,a[N],bin[M],c[M],lm,ans;int rdn(){ int ret=0;bool fx=1;char ch=getchar(); while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)fx=0;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘) ret=(ret<<3)+(ret<<1)+ch-‘0‘,ch=getchar(); return fx?ret:-ret;}int main(){ int tp=0; n=rdn();for(int i=1;i<=n;i++)a[i]=rdn(),tp=max(tp,a[i]); while(tp)lm++,tp>>=1; lm--; bin[0]=1;for(int i=1;i<=lm;i++)bin[i]=bin[i-1]<<1; for(int i=1;i<=n;i++) { int d=0; for(int j=0;j<=lm&&bin[j]<=a[i];j++) if(a[i]&bin[j])d=max(d,c[j]); d++; for(int j=0;j<=lm&&bin[j]<=a[i];j++) if(a[i]&bin[j])c[j]=max(c[j],d); } for(int j=0;j<=lm;j++)ans=max(ans,c[j]); printf("%d\n",ans); return 0;}
Bzoj 4300 excellent question -- DP