Submit: 1120 Solved: 609
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 2 3
Sample Output
HINT
n<=100000,ai<=2*10^9
Source
【题解】
设f[i],二进制中倒数第i位为1的数(其他位置不一定)所形成的数列的最长长度;
【代码】
#include <cstdio> #include <algorithm> using namespace std; const int MAXN = 101000; int n,ans = 0; int x; int f[31] = { 0 }; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &x); int temp = 0; for (int j = 0; j <= 30; j++) if (x & (1 << j)) temp = max(temp, f[j] + 1); for (int j = 0; j <= 30; j++) if (x & (1 << j)) f[j] = temp; ans = max(ans, temp); } printf("%d\n", ans); return 0; }