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