[题目链接]

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

[算法]

        记Fi表示二进制表示下第i位为1的最长序列

        可以通过枚举二进制的每一位进行转移

        时间复杂度 : O(NlogV)

[代码]

         

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int f[30];

template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}
int main()
{
        
        int n;
        read(n);
        for (int i = 1; i <= n; i++)
        {
                int x;
                read(x);
                int value = 0;
                for (int j = 0; j < 31; j++)
                        if (x & (1 << j)) chkmax(value , f[j] + 1);
                for (int j = 0; j < 31; j++)
                        if (x & (1 << j)) chkmax(f[j] , value);
        }
        int ans = 0;
        for (int i = 0; i < 31; i++) chkmax(ans , f[i]);
        printf("%d\n" , ans);
        
        return 0;
    
}

 

相关文章:

  • 2021-12-02
  • 2022-12-23
  • 2022-02-09
  • 2021-06-21
  • 2021-12-20
  • 2021-08-11
  • 2022-01-25
  • 2021-08-20
猜你喜欢
  • 2021-10-17
  • 2021-12-21
  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2022-02-11
相关资源
相似解决方案