51 NOD 1406 and query

    We know that a number S will contribute 1 to all its subsets S', but if we directly enumerate the subset is 3^(log2 1000000), it will blow up; if we directly change each bit with 1 into Pushing 0 down will also cool down, because there will be a lot of repetitions.

    But we found that the second method actually counts the number of ordered path schemes. We try to make it unordered, and the contribution is exactly 1.

    Specifically, we enumerate the number of bits in the outer layer, and the inner layer contributes all the numbers whose bit is 1 to the number that turns this bit into 0, which is disordered.

 

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1000000;
int n,f[maxn*2+5],ci[35];

inline int read(){
	int x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar());
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x;
}

void W(int a){ if(a>=10) W(a/10); putchar(a%10+'0');}  

inline void dp(){
	for(int i=0;i<20;i++)
	    for(int j=maxn;j;j--) if(j&ci[i]) f[j^ci[i]]+=f[j];
}

inline void output(){
	for(int i=0;i<=maxn;i++) W(f[i]),puts("");
}

int main(){
	ci [0] = 1;
	for(int i=1;i<=20;i++) ci[i]=ci[i-1]<<1;
	n=read();
	for(int i=1;i<=n;i++) f[read()]++;
	dp();
	output();
	return 0;
}

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324523048&siteId=291194637