Bzoj 4300 excellent question -- DP

Source: Internet
Author: User

Question: https://www.lydsy.com/JudgeOnline/problem.php? Id = 4300

Consider which J can be transferred from DP [I], that is, a [J] & A [I]! 0, that is, there is at least one common 1. Therefore, the value of DP [] in a [] of 1 is recorded on 30 bits, it will be transferred.

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=1e5,M=35;int n,a[N],bin[M],c[M],lm,ans;int rdn(){  int ret=0;bool fx=1;char ch=getchar();  while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)fx=0;ch=getchar();}  while(ch>=‘0‘&&ch<=‘9‘) ret=(ret<<3)+(ret<<1)+ch-‘0‘,ch=getchar();  return fx?ret:-ret;}int main(){  int tp=0;  n=rdn();for(int i=1;i<=n;i++)a[i]=rdn(),tp=max(tp,a[i]);  while(tp)lm++,tp>>=1; lm--;  bin[0]=1;for(int i=1;i<=lm;i++)bin[i]=bin[i-1]<<1;  for(int i=1;i<=n;i++)    {      int d=0;      for(int j=0;j<=lm&&bin[j]<=a[i];j++)    if(a[i]&bin[j])d=max(d,c[j]);      d++;      for(int j=0;j<=lm&&bin[j]<=a[i];j++)    if(a[i]&bin[j])c[j]=max(c[j],d);    }  for(int j=0;j<=lm;j++)ans=max(ans,c[j]);  printf("%d\n",ans);  return 0;}

 

Bzoj 4300 excellent question -- DP

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.