首页 > 代码库 > bzoj4300 绝世好题
bzoj4300 绝世好题
传送门: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; }
bzoj4300 绝世好题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。