N count
Calculate the number of K numbers from N to the same or, and the total value (CNK values (which may be the same) obtained in all cases is
K from 1 to n
Output n count
At the beginning, I had no thoughts on this question.
I didn't mean the approximate range of N numbers. I wanted to use a backpack.
The result shows that this solution is used.
For example, split four numbers 1, 2, 10, and 1. Currently, K numbers are used.
0001
0010
1010
0001
For the fourth digit, if the number of K is different or the value is 0, it is equal to the number of 0 * solutions.
In some schemes, if the two numbers are different or the latter is 1, the number is equal to 1 *.
We can see that the fourth digit has 1, so the number of solutions with an exclusive or 1 is C31 * C11. Likewise, the second digit has 2 1, which is C21 * C21.
The answer is
(1 <3) * C31 * C11 + (1 <1) C21 * C21 + (1 <0) C21 * C21
Prepare the c1000 1000 table in advance.
#include <iostream>#include <cmath>#include <cstdio>#include <cstring>#include <vector>using namespace std;int C[1111][1111];const int MOD=1e6+3;#define LL long longint main(){#ifndef ONLINE_JUDGE freopen("G:/in.txt","r",stdin); //freopen("G:/myout.txt","w",stdout);#endifint N;C[0][0]=1;for(int i=1;i<=1000;i++){for(int j=0;j<=i;j++){if(j==0) C[j][i]=1;else C[j][i]=(C[j][i-1]+C[j-1][i-1])%MOD;}}while(scanf("%d",&N)!=EOF){int tmp;int num[31];memset(num,0,sizeof(num));for(int i=1;i<=N;i++){scanf("%d",&tmp);for(int i=0;i<=30;i++)if((tmp>>i)&1)num[i]++;}int ans[1111];memset(ans,0,sizeof(ans));for(int i=1;i<=N;i++)for(int j=0;j<=30;j++)for(int k=1;k<=num[j] && k<=i;k+=2){ans[i]=(ans[i]+(LL)(1<<j)%MOD*(LL)C[k][num[j]]%MOD*(LL)C[i-k][N-num[j]]%MOD)%MOD;}for(int i=1;i<=N;i++)printf("%d%c",ans[i],i==N?'\n':' ');}return 0;}
HDU 4810 wall painting [binary + exclusive or + brute force enumeration]