51nod 1406 and query

Source: Internet
Author: User

Garbage player Practice DP

Consider that for a number, to be able to express it will also be able to make some of its 1 bits into a number of 0 to represent it.

So with the large number of updates small, it is easy to think of this large number of a 1 bit into 0

But there's still going to be a duplication of things.

For example, 10010 is updated by 10110 and 11010, but these two numbers are updated by 11110 to

Then the DP plus one dimension, F[i][zt] indicates that the ZT is currently only updated by the number of the first I bit is 1, for the update of the former i-1 bit can be added directly, the update of the I-bit is processed in the current for loop

This will not be repeated, but also can be found that this is a backpack-like things, so I can also save the dimension of the

#include <cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar ();  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;}voidWriteintd) {    if(d<0) {Putchar ('-');d =-D;} if(d>=Ten) Write (d/Ten); Putchar (d%Ten+'0');}intf[1100000];intMain () {intn,x,mx=0; N=read (); Memset (F,0,sizeof(f));  for(intI=1; i<=n;i++) {x=read (), f[x]++; MX=Max (mx,x); }             for(intI= A; i>=0; i--)         for(intzt=1; zt<=mx;zt++)            if(zt& (1<<i)) f[zt^ (1<<i)]+=F[ZT]; f[0]=N;  for(intI=0; i<= -; i++) {write (f[i]); Puts (""); }    return 0;}

51nod 1406 and query

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.