zoukankan      html  css  js  c++  java
  • bzoj4300-绝世好题

    题意

    求长度为 (n) 的序列 (a) 的最长子序列 (b) 的长度,满足 (forall iin [2, ext{len}(b)],b_i&b_{i-1} e 0)

    分析

    最长子序列模型,设 (f_i) 为前 (i) 个,必须选 (i) 的最长满足要求的子序列,那它其实可以从 (a_j) 满足其中含有某个 (a_i) 的位,转移过来。注意到这个转移只与含有的位有关,设 (g_k) 表示到现在位置 (k) 位上有 1 的 (a_i)(f_i) 的最大值。直接转移即可。复杂度为 (O(nlog w))

    代码

    #include<bits/stdc++.h>
    using namespace std;
    inline char nchar() {
    	static const int bufl=1<<20;
    	static char buf[bufl],*a,*b;
    	return a==b && (b=(a=buf)+fread(buf,1,bufl,stdin),a==b)?EOF:*a++;
    }
    inline int read() {
    	int x=0,f=1;
    	char c=nchar();
    	for (;!isdigit(c);c=nchar()) if (c=='-') f=-1;
    	for (;isdigit(c);c=nchar()) x=x*10+c-'0';
    	return x*f;
    }
    const int maxn=1e5+1;
    const int maxj=31;
    int n,f[maxn],g[maxj],ans=1;
    inline void Max(int &x,int y) {x=max(x,y);}
    int main() {
    #ifndef ONLINE_JUDGE
    	freopen("test.in","r",stdin);
    #endif
    	n=read();
    	for (int i=1;i<=n;++i) {
    		int &fi=f[i]=1,ai=read();
    		for (int j=0;j<maxj;++j) if ((ai>>j)&1) Max(fi,g[j]+1);
    		for (int j=0;j<maxj;++j) if ((ai>>j)&1) Max(g[j],fi);
    		Max(ans,fi);
    	}
    	printf("%d
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    Spring——框架
    Spring——简介
    系统常识——系统碎片
    php5.3.3以上重启php-fpm的方法
    linux后端跑redis
    php的post
    微信场景二维码
    phantomjs和selenium模拟登陆qq空间
    python登录知乎
    python的request抓https的警告问题
  • 原文地址:https://www.cnblogs.com/owenyu/p/7543262.html
Copyright © 2011-2022 走看看