1. 程式人生 > >bzoj 4300 絕世好題 —— 思路

bzoj 4300 絕世好題 —— 思路

最大 include oid span 元素 tps lin urn div

題目:https://www.lydsy.com/JudgeOnline/problem.php?id=4300

記錄一下 mx[j] 表示以第 j 位上是1的元素結尾的子序列長度最大值,轉移即可。

代碼如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const xn=1e5+5,xm=32;
int n,a[xn],mx[xm],bin[xm];
int rd()
{
  int ret=0,f=1; char
ch=getchar(); while(ch<0||ch>9){if(ch==-)f=0; ch=getchar();} while(ch>=0&&ch<=9)ret=(ret<<3)+(ret<<1)+ch-0,ch=getchar(); return f?ret:-ret; } void init() { bin[0]=1; for(int i=1;i<=31;i++)bin[i]=(bin[i-1]<<1); } int main() { n=rd(); int ans=0
; init(); for(int i=1,x;i<=n;i++) { x=rd(); int t=0; for(int j=0;j<=31;j++) if(x&bin[j])t=max(t,mx[j]+1); ans=max(ans,t); for(int j=0;j<=31;j++) if(x&bin[j])mx[j]=max(mx[j],t); } printf("%d\n",ans); return 0; }

bzoj 4300 絕世好題 —— 思路