【BZOJ4300】绝世好题(水)
来源:互联网 发布:网络捕鱼游戏加盟代理 编辑:程序博客网 时间:2024/05/13 10:39
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
Sample Output
2
HINT
n<=100000,ai<=2*10^9
题解:
真是好(shui)题。
递推,不多说,上代码。
#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<math.h>#define ll long long#define inf 0x7f7f7f7fusing namespace std;int n,dp[35],ans;int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) { int x,cal=0; scanf("%d",&x); for(int j=0;j<=30;j++) if((x&(1<<j))!=0) cal=max(cal,dp[j]+1); for(int j=0;j<=30;j++) if((x&(1<<j))!=0) dp[j]=max(dp[j],cal); } for(int i=0;i<=30;i++) ans=max(ans,dp[i]); printf("%d\n",ans);}
1 0
- 【BZOJ4300】绝世好题(水)
- 【BZOJ4300】绝世好题
- 【bzoj4300】【绝世好题】
- BZOJ4300 绝世好题
- 【bzoj4300】绝世好题
- [BZOJ4300] 绝世好题
- [BZOJ4300]绝世好题
- bzoj4300 绝世好题
- [BZOJ4300]绝世好题
- 【bzoj4300】绝世好题
- bzoj4300 绝世好题
- 【bzoj4300】绝世好题
- bzoj4300: 绝世好题
- BZOJ4300 绝世好题
- BZOJ4300 绝世好题
- bzoj4300 绝世好题
- BZOJ4300 绝世好题
- bzoj4300: 绝世好题(dp)
- POJ 1990 MooFest (树状数组)
- bzoj3143: [Hnoi2013]游走
- 对象输入输出流_ObjectInputStream类与ObjectOutputStream类
- L1-011. A-B
- 代码模板:python-基础-2(条件语句)
- 【BZOJ4300】绝世好题(水)
- 【JavaWeb】Model1和Model2
- 正则中圆括号()方括号[]大括号{}的区别和用法
- 如何选择更优质的IDC机房?
- Python进阶(四)-浅谈Python闭包
- 练习
- POJ-3414
- 餐馆就餐问题
- Bmob后端云的集成与使用