BZOJ4300 絕世好題 dp

2022-02-27 20:52:38 字數 998 閱讀 4088

給定乙個長度為n的數列ai,求ai的子串行bi的最長長度,滿足bi&bi-1!=0(2<=i<=len)。

輸入檔案共2行。

第一行包括乙個整數n。

第二行包括n個整數,第i個整數表示ai。

輸出檔案共一行。

包括乙個整數,表示子串行bi的最長長度。

1 2 3

n<=100000,ai<=2*10^9

按位dp

f[i] = max (存在a[i]二進位制某位和a[j]同時為1)

這樣做是o(

n2)的

我們可以將二進位制每一位為1時的最優答案儲存下來,就可以做到o(

32∗n)

的複雜度

#include

#include

#include

#include

#define ll long long int

#define rep(i,n) for (int i = 1; i <= (n); i++)

using

namespace

std;

const

int maxn = 100005,maxm = 100005,inf = 1000000000;

inline

int rd()

while (c >= 48 && c <= 57)

return out * flag;

}int n,a[maxn][40],f[maxn],mx[40];

int main()

}for (int j = 1; j <= 32; j++)

if (a[i][j])

mx[j] = max(mx[j],f[i]);

}int ans = 0;

rep(i,32) ans = max(ans,mx[i]);

printf("%d\n",ans);

return

0;}

BZOJ 4300 絕世好題 dp

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...

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...