HDU - 4810 Wall Painting

Ms.Fang loves painting very much. She paints GFW(Great Funny Wall) every day. Every day before painting, she produces a wonderful color of pigments by mixing water and some bags of pigments. On the K-th day, she will select K specific bags of pigments and mix them to get a color of pigments which she will use that day. When she mixes a bag of pigments with color A and a bag of pigments with color B, she will get pigments with color A xor B. 
When she mixes two bags of pigments with the same color, she will get color zero for some strange reasons. Now, her husband Mr.Fang has no idea about which K bags of pigments Ms.Fang will select on the K-th day. He wonders the sum of the colors Ms.Fang will get with  different plans. 

For example, assume n = 3, K = 2 and three bags of pigments with color 2, 1, 2. She can get color 3, 3, 0 with 3 different plans. In this instance, the answer Mr.Fang wants to get on the second day is 3 + 3 + 0 = 6. 
Mr.Fang is so busy that he doesn’t want to spend too much time on it. Can you help him? 
You should tell Mr.Fang the answer from the first day to the n-th day.

InputThere are several test cases, please process till EOF. 
For each test case, the first line contains a single integer N(1 <= N <= 10 3).The second line contains N integers. The i-th integer represents the color of the pigments in the i-th bag.OutputFor each test case, output N integers in a line representing the answers(mod 10 6 +3) from the first day to the n-th day.Sample Input

4
1 2 10 1

Sample Output

14 36 30 8

一看到异或首先应该想到位运算,按位分析情况。

还有一个定理:cm(n+1)=c(m-1)n+cmn;

题意:第k天选k种颜色,对这k个数进行异或,再把所有可能的异或值进行求和。
解题思路:因为是异或,不用考虑进位,所以可以按位分析。只有异或的1的个数为奇数,该数才会被计入和中。

附ac代码:
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cmath>
 4 #include <string>
 5 #include <cstring>
 6 #include <algorithm>
 7 #include <iomanip>
 8 #include <map>
 9 #include <set>
10 using namespace std;
11 typedef long long ll;
12 const ll mod = 1e6+3;
13 const int maxn = 111111;
14 ll nu[maxn];
15 int bt[maxn];
16 int cc[1011][1011];
17 int main() {
18     ll n;
19     ll sum=0;
20     for(int i=0;i<1011;i++)     //组合数的打表
21     {
22         for(int j=0;j<=i;++j)
23         {
24             if(!j) cc[j][i]=1;
25             else cc[j][i]=(cc[j][i-1]%mod+cc[j-1][i-1])%mod;
26         }
27     }
28     while(cin>>n)
29     {
30         memset(bt,0,sizeof(bt));
31         sum=0;
32         for(int i=0;i<n;++i)
33         {
34             cin>>nu[i];
35             sum=(sum%mod+nu[i]%mod)%mod;
36         }
37   //      cout<<sum<<" ";
38         for(int i=0;i<=32;++i)
39         {
40             for(int j=0;j<n;++j)
41             {
42                 if((nu[j]>>i)&1)    //统计每位1的个数。
43                     bt[i]++;
44             }
45         }
46         for(int i=1;i<=n;++i)
47         {
48             sum=0;
49             for(int j=0;j<=32;++j)
50             {
51                 for(int k=1;k<=bt[j]&&k<=i;k+=2)
52                 {
53                     sum=(sum%mod+ll(1<<j)%mod*(cc[k][bt[j]]%mod*cc[i-k][n-bt[j]]%mod)%mod)%mod;
54                 }
55             }
56             cout<<sum;
57             if(i!=n)
58             cout<<" ";
59         }
60         cout<<endl;
61     }
62     return 0;
63 }
View Code

 

posted @ 2018-01-24 15:20  euzmin  阅读(194)  评论(0编辑  收藏  举报