0
点赞
收藏
分享

微信扫一扫

BZOJ 4300 绝世好题 动态规划


题目大意:给定一个序列a,求一个子序列b使得bi and bi−1≠0且|b|最大

题。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 100100
using namespace std;
int n,ans;
int f[32];
int main()
{
    int i,j,x;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&x);
        int temp=0;
        for(j=0;j<=30;j++)
            if(x&(1<<j))
                temp=max(temp,f[j]+1);
        for(j=0;j<=30;j++)
            if(x&(1<<j))
                f[j]=temp;
        ans=max(ans,temp);
    }
    cout<<ans<<endl;
    return 0;
}


举报

相关推荐

0 条评论