码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj4300 绝世好题

时间:2017-06-06 22:02:25      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:reg   cout   fine   ring   个数   alt   .com   geo   color   

传送门: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 绝世好题

标签:reg   cout   fine   ring   个数   alt   .com   geo   color   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!