Problem 4300. --Excellent title
4300: Fantastic title time limit:1 Sec Memory limit:128 MB
submit:1597 solved:814
[Submit] [Status] [Discuss] Description given an n-length sequence AI, the longest length of the AI's subsequence bi is satisfied with bi&bi-1!=0 (2<=i<=len).
Input file total 2 rows. The first line includes an integer n. The second line includes n integers, and the first integer represents AI.
Output file has a single row. Includes an integer that represents the longest length of the subsequence bi.
Sample Input3
1 2 3Sample Output2HINT
N<=100000,ai<=2*10^9
Source
by Oxer
[Submit] [Status] [Discuss]
Greedy, using $f[i]$ to denote the longest-oldest sequence length of the ending number I-bit 1.
1 Importjava.util.Arrays;2 ImportJava.util.Scanner;3 4 Public classMain {5 6 Public Static voidMain (String args[]) {7 8Scanner in =NewScanner (system.in);9 Tenintn =in.nextint (); OneintF[] =New int[35]; A -Arrays.fill (F, 0); - the for(inti = 1; I <= N; ++i) { - -intnum = In.nextint (), TMP = 0; - + for(intj = 0; J <= 30; ++j) -if((Num >> j) & 1) = = 1) +TMP =Math.max (TMP, f[j]); A at for(intj = 0; J <= 30; ++j) -if((Num >> j) & 1) = = 1) -F[J] = Math.max (F[j], TMP + 1); - - } - inintAns = 0; - to for(inti = 0; I <= 30; ++i) +Ans =Math.max (ans, f[i]); - the System.out.println (ans); * $ in.close ();Panax Notoginseng - } the +}
@Author: Yousiki
Bzoj 4300: good title