4300: 绝世好题
来源:互联网 发布:涉密数据恢复资质 编辑:程序博客网 时间:2024/04/28 16:46
4300: 绝世好题
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1328 Solved: 724
[Submit][Status][Discuss]
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
1 2 3
Sample Output
2
HINT
n<=100000,ai<=2*10^9
Source
By Oxer
对于条件bi & bi-1 != 0,,要满足它,只要满足!= 0即可,也就是说,bi & bi-1的值是多少,根本无关紧要
令fi为以位置i结尾的最长子序列长度
定义gi为以最后一个数字转换为二进制数码后第i位为1的最长子序列长度
这样转移和更新log就完成了
#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<vector>#include<queue>#include<set>#include<map>#include<stack>#include<bitset>#include<ext/pb_ds/priority_queue.hpp>using namespace std;const int maxn = 1E5 + 10;int n,ans,a[maxn],f[maxn],g[31];int main(){#ifdef DMCfreopen("DMC.txt","r",stdin);#endifcin >> n;for (int i = 1; i <= n; i++) scanf("%d",&a[i]);for (int i = 1; i <= n; i++){for (int j = 0; j <= 30; j++)if (a[i]&(1<<j)) f[i] = max(f[i],g[j]);++f[i]; ans = max(ans,f[i]);for (int j = 0; j <= 30; j++)if (a[i]&(1<<j)) g[j] = max(g[j],f[i]);}cout << ans;return 0;}
0 0
- 4300: 绝世好题
- 4300: 绝世好题
- 【bzoj 4300】绝世好题
- 【BZOJ】4300 绝世好题
- BZOJ 4300: 绝世好题
- HYSBZ 4300 绝世好题
- BZOJ 4300 绝世好题
- 【bzoj 4300】绝世好题
- bzoj 4300: 绝世好题
- BZOJ 4300 绝世好题 递推
- BZOJ 4300 绝世好题 动态规划
- BZOJ 4300(绝世好题-dp)
- 【递推】BZOJ 4300:绝世好题
- [BZOJ 4300] 绝世好题 · 乱搞
- BZOJ 4300: 绝世好题【DP
- 【54.38%】【BZOJ 4300】绝世好题
- bzoj 4300 绝世好题(dp)
- BZOJ 4300 绝世好题(DP)
- 类对象复制
- UE4 生成C++环境
- 机器学习算法(分类算法)—Rosenblatt感知机
- 单核处理器、多核处理器、多处理器与多线程编程
- VC 虚拟打印
- 4300: 绝世好题
- Python之基本语法join函数,模块处理
- 100道动态规划——12 UVA 1252 Twenty Questions 状态压缩,记忆化搜索,带一点小小的优化
- 关于图片onload事件兼容性处理, 谷歌浏览器版本 56.0.2896.3 (64-bit) 微信客户端浏览器 canvas篇
- chapter 6 exercise 6_12
- MyBatis xml配置文件详解
- 软件工程论文注意事项
- for循环中setTimeout使用注意
- 集成JSPatch平台步骤