Great title HYSBZ-4300 (bit DP)

Source: Internet
Author: User

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). The
Input
file has a total of 2 rows. The
First line includes an integer n. The second line of the
includes n integers, and the first integer represents AI. The
output
outputs a single line of files. The
includes an integer that represents the longest length of the subsequence bi.
Sample Input
3
1 2 3
Sample Output
2
Hint
N<=100000,ai<=2*10^9
DP represents the current number of digits can be reached The maximum length. The
DP transfer decision condition is a[i]& (1<

 #include <iostream> #include <cstdio> #include <cstring> #include <
Algorithm> using namespace std;
typedef long Long LL;
const int MAXN = 1000011;
int N,a[maxn],ans;

int f[31];
    int main () {cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    int now;
        for (int i=1;i<=n;i++) {now=0;
    for (int j=0;j<=30;j++) if ((a[i]& (1<<j))!=0) Now=max (F[j],now);
    now++;
    for (int j=0;j<=30;j++) if (a[i]& (1<<j)!=0) F[j]=max (F[j],now);
    } for (int i=0;i<=30;i++) Ans=max (Ans,f[i]);
printf ("%d\n", ans); }

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.