【bzoj4300】【绝世好题】
来源:互联网 发布:pp助手正版mac 编辑:程序博客网 时间:2024/04/28 05:18
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
对于100%的数据,1<=n<=100000,ai<=10^9。
题解:保存一下每一位&运算之后为1的最大长度。每次枚举每一位更新一下即可。
使用一点黑科技可以让代码短很多。
代码:
#include<iostream>#include<cstdio>#include<algorithm>int x,ans,temp,n,a[40];using namespace std;int main(){ scanf("%d",&n); for (int i=1;i<=n;i++){ scanf("%d",&x);temp=0; for (int j=x;j;j-=j&(-j)) temp=max(temp,a[__builtin_ctz(j)]);ans=max(ans,++temp); for (int j=x;j;j-=j&(-j)) a[__builtin_ctz(j)]=temp; } cout<<ans<<endl;}
0 0
- 【BZOJ4300】绝世好题
- 【bzoj4300】【绝世好题】
- BZOJ4300 绝世好题
- 【bzoj4300】绝世好题
- [BZOJ4300] 绝世好题
- [BZOJ4300]绝世好题
- bzoj4300 绝世好题
- [BZOJ4300]绝世好题
- 【bzoj4300】绝世好题
- bzoj4300 绝世好题
- 【bzoj4300】绝世好题
- bzoj4300: 绝世好题
- BZOJ4300 绝世好题
- BZOJ4300 绝世好题
- bzoj4300 绝世好题
- BZOJ4300 绝世好题
- 【bzoj4300】绝世好题 二进制
- bzoj4300: 绝世好题 - DP
- Java 的四大引用:强引用、软引用、弱引用和虚引用
- 可拖动的TextView
- opencv2-遍历图像像素的14种方法
- 软件架构师应该知道的97件事之概括1-15
- python在web中输出word文档
- 【bzoj4300】【绝世好题】
- session.put() 和 session.setAttribute()
- zoj3762Alice's Print Service
- JAVA 上机作业8.1
- 运行循环RunLoop原理剖析
- ELKStack读取文件
- 68Text Justification
- hdoj 1229 还是a+b
- 数组去重