首页 > 其他 > 详细

bzoj4300 绝世好题

时间:2017-06-06 21:44:05      阅读:323      评论:0      收藏:0      [点我收藏+]

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4300

【题解】

令f[i]表示二进制下上一个数第i位为1的最大长度

那么至少有一位这个数和上一个数都为1,就可以转移了。

技术分享
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + 10, N = 30 + 10;
const int mod = 1e9+7;

# define RG register
# define ST static

int n, a[M];
int f[N];

int main() {
    cin >> n;
    for (int i=1; i<=n; ++i) scanf("%d", a+i);
    for (int i=1; i<=n; ++i) {
        int t = 0;
        for (int j=0; j<=30; ++j)
            if(a[i]&(1<<j)) t = max(t, f[j]);
        ++t;
        for (int j=0; j<=30; ++j)
            if(a[i]&(1<<j)) f[j] = t;
    }
    int ans = 0;
    for (int i=0; i<=30; ++i) ans = max(ans, f[i]);
    cout << ans;
    return 0;
}
View Code

 

bzoj4300 绝世好题

原文:http://www.cnblogs.com/galaxies/p/bzoj4300.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!