zoukankan      html  css  js  c++  java
  • bzoj 4300: 绝世好题

    4300: 绝世好题

    Time Limit: 1 Sec  Memory Limit: 128 MB

    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


    Source

    #include<cstdio>
    #define N 100010
    inline int max(int a,int b){return a>b?a:b;}
    inline int read()
    {
        int tmp=0;
        char ch=getchar();
        while(ch<'0'||ch>'9') ch=getchar();
        while(ch>='0'&&ch<='9'){tmp=tmp*10+ch-'0';ch=getchar();}
        return tmp;
    }
    int t,n,a[N],f[33],ans;
    int main()
    {
        n=read();
        for(int i=0;i<n;i++)
        {
            t=read();
            int tmp=0;
            for(int j=0;j<31;j++)
            if(t&(1<<j)) tmp=max(f[j]+1,tmp);
            for(int j=0;j<31;j++)
            if(t&(1<<j)) f[j]=tmp;
            ans=max(ans,tmp);
        }
        printf("%d",ans);
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    独木舟上的旅行
    会场安排问题
    喷水装置(二)
    喷水装置(一)
    款待奶牛
    整理书本
    贪心算法基本思想和典型例题(转)
    贪心算法
    太乱了,不要了
    Runtime Error:Floating point exception 不知道拿错了
  • 原文地址:https://www.cnblogs.com/lkhll/p/6110815.html
Copyright © 2011-2022 走看看