首页 > 其他 > 详细

bzoj4300绝世好题

时间:2016-08-15 22:08:35      阅读:266      评论:0      收藏:0      [点我收藏+]

bzoj4300绝世好题

题意:

给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0。n≤100000,ai≤10^9。

题解:

用f[i]表示当前二进制i为1的最长子序列长度。每次求所有((1<<i)&bi)==1的f[i]最大值max,将所有((1<<i)&bi)==1的f[i]变为max+1。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define inc(i,j,k) for(int i=j;i<=k;i++)
 5 #define maxn 100010
 6 using namespace std;
 7 
 8 inline int read(){
 9     char ch=getchar(); int f=1,x=0;
10     while(ch<0||ch>9){if(ch==-)f=-1; ch=getchar();}
11     while(ch>=0&&ch<=9)x=x*10+ch-0,ch=getchar();
12     return f*x;
13 }
14 int n,a,f[40],tot;
15 int main(){
16     n=read();
17     inc(i,1,n){
18         a=read(); tot=0;
19         inc(j,0,30)if(a&(1<<j))tot=max(tot,f[j]); inc(j,0,30)if(a&(1<<j))f[j]=tot+1;
20     }
21     tot=0; inc(i,0,30)tot=max(tot,f[i]); printf("%d",tot); return 0;
22 }

 

20160812

bzoj4300绝世好题

原文:http://www.cnblogs.com/YuanZiming/p/5774474.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!