description
now give you a number sequence ai, you need to calculate the longest length of subsequence bi, meet the requirements of bi & bi-1 is not equal to zero. (2<=i<= len).
input
input contain two lines, the first line contains a number n, the second line continues n integers, which representation ai, n <=100000, ai<= 2 * 10^9.
output
output contain one line, output the length of longest subsequence bi satisfying the requirements.
sample input
31 2 3
sample output
2
題意:思路:既然要求此項和前一項&不為0,我們知道當兩個數所對應的二進位制中相同位都為1,那麼這兩個數相與才一定不為0;給定乙個長度為n的數列ai,求ai的子串行bi的最長長度,滿足bi&bi-1!=0 (2<=i<=n)。
(不一定是連續的啊。。)
這裡我們dp記錄二進位制中所對應的1的當前序列的最長值,找出最長序列記得要把這個數的三個位置都變成最長的長度,
#include#include#include#includeusing namespace std;int dp[32];
int main()
ans=max(ans,res);
for(i=0;i<=30;i++)
}printf("%d\n",ans);
return 0;
}
BZOJ 4300 絕世好題 Dp
time limit 1 sec memory limit 128 mb submit 2197 solved 1175 submit status discuss 給定乙個長度為n的數列ai,求ai的子串行bi的最長長度,滿足bi bi 1 0 2 i len 輸入檔案共2行。第一行包括乙個整數n...
BZOJ4300絕世好題(DP)
description 給定乙個長度為n的數列ai,求ai的子串行bi的最長長度,滿足bi bi 1 0 2 i len input 輸入檔案共2行。第一行包括乙個整數n。第二行包括n個整數,第i個整數表示ai。output 輸出檔案共一行。包括乙個整數,表示子串行bi的最長長度。sample in...
BZOJ 4300 絕世好題 dp
dp i 表示二進位制的第i位為1時的最大值,然後從左到右dp include include include using namespace std define b i 1 i const int maxn 100009 const int n 31 int dp 40 n int main p...