Bzoj4300 great problem

Source: Internet
Author: User

Time limit:1 Sec Memory limit:128 MB
submit:1325 solved:722

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

Just started to be frightened, thought, originally is a similar LIS DP.

F[J] represents the sequence length of the last number of sequences in binary J bits 1. Specific transfer See Code

1 /*by Silvern*/2#include <iostream>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <algorithm>7 #defineLL Long Long8 using namespacestd;9 Const intmxn=100010;Ten intRead () { One     intx=0, f=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnx*F; the } - intN; - intf[ +],a[mxn],b[ +]; - intMain () { +n=read (); -     inti,j; +      for(i=1; i<=n;i++) Aa[i]=read (); atb[0]=1; -      for(j=1; j<= -; j + +) -B[j]= (b[j-1]<<1); -      for(i=1; i<=n;i++){ -         inttmp=0; -          for(j=0;j< to; j + +) in             if(A[i]&b[j]) Tmp=max (tmp,f[j]+1); -          for(j=0;j< to; j + +) to             if(A[i]&b[j]) f[j]=Max (f[j],tmp); +     } -     intans=0; the      for(j=0;j< to; j + +) ans=Max (ans,f[j]); *printf"%d\n", ans); $     return 0;Panax Notoginseng}

Bzoj4300 great problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.