绝世好题bzoj4300

时间:2022-10-08 19:53:40

Description

给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len)。

Input

输入文件共2行。
第一行包括一个整数n。
第二行包括n个整数,第i个整数表示ai。

Output

输出文件共一行。
包括一个整数,表示子序列bi的最长长度。

Sample Input

3
1 2 3

Sample Output

2

HINT

n<=100000,ai<=2*10^9

递推

f[x]表示相应二进制位为1时的最优解

每一次输入一个数,二进制分解,取为1的f值的最大长度

再将其加1,取代对应的f值

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int f[],x,n,ans;
int main()
{int i,cnt,z;
cin>>n;
for (i=;i<=n;i++)
{
scanf("%d",&x);
cnt=,z=;
int xx=x;
while (x)
{
cnt++;
if (x%==)
{
z=max(z,f[cnt]);
}
x/=;
}
cnt=;
while (xx)
{
cnt++;
if (xx%==)
{
f[cnt]=max(f[cnt],z+);
ans=max(ans,f[cnt]);
}
xx/=;
}
}
cout<<ans;
}