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

    BZOJ4300 绝世好题

    题目传送门

    题解

    比较简单的(DP),记(f[i])表示第(i)位为1,最长的长度为多少。只需要枚举每一个数字,对于这个数字二进制下为1的那一位进行更新就行了。

    code

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    bool Finish_read;
    template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
    template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
    template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('
    ');}
    template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
    /*================Header Template==============*/
    const int maxn=1e5+500;
    int n;
    int a[maxn];
    int f[40];
    /*==================Define Area================*/
    int main() {
    	read(n);
    	for(int i=1;i<=n;i++) {
    		read(a[i]);
    	}
    	for(int i=1;i<=n;i++) {
    		int p=a[i];
    		int len=0;
    		for(int j=0;j<=30;j++) {
    			if(p&(1<<j)) len=max(len,f[j]+1);
    		}
    		for(int j=0;j<=30;j++) {
    			if(p&(1<<j)) f[j]=len;
    		}
    	}
    	int ans=0;
    	for(int i=0;i<40;i++) {
    		ans=max(ans,f[i]);
    	}
    	printf("%d
    ",ans);
    	return 0;
    }
    
    「我不敢下苦功琢磨自己,怕终于知道自己并非珠玉;然而心中既存着一丝希冀,便又不肯甘心与瓦砾为伍。」
  • 相关阅读:
    【读书笔记】房龙-人类的故事
    【读书笔记】曼昆-经济学原理:宏观经济学分册
    【读书笔记】曼昆-经济学原理:微观经济学分册
    ES6数组去重
    switch语句
    if语句的优化
    程序的三大结构
    NaN
    js中常见的数据类型
    变量的命名规则
  • 原文地址:https://www.cnblogs.com/Apocrypha/p/9431657.html
Copyright © 2011-2022 走看看