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.
Input
There 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.
Output
For 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
题意:
题意:给定n个数,进行n次操作。对第i次操作,要求你从n个数里面任选i个数,用这i个数异或得到一个新数,并把所有新数相加(可以重复加)。对每次操作,输出新数相加之和。
思路:考虑二进制中的1,只有奇数个同位的1 相异或 才能使该进制位的1不丢失。这样考虑每个二进制位上的1对结果做出的贡献,然后累加贡献值就可以了。
如在第j位有num[j]个1,现在要从这n个数里面选i个数异或,对第j位的1来说,我们只需要考虑1不丢失的所有方案
=从num[j]个1里面选奇数个1(这里设选k个),再从n-num[j]里面选出剩下i-k个 = C(num[j], k)*C(n-num[j], i-k)
得到贡献值 = 方案数 * 该二进制位上1的价值 = C(num[j], k) * C(n-num[j], i-k) * (1< 比如一共给了十五个数,第三位上有7个1,那么则有3个0,假设当前要取5个数,由于二进制第三位的权值是2^3,那么第三位只要产生一个1就相当于增加了8,现在要解决的就是第三位能产生几个1,由异或规律可知当选择的1的数量为奇数个的时候最后异或得到的结果是1,要取5个数,则取奇数个1的情况为取一个1,三个1,五个1,由组合数学知识可知,第三位能产生1的数量就为C7,1*C8,4+C7,3*C8,2+C7,5*C8,0(这里的C为组合数学中从n个数里选i个数那个Cn,i) 则第三位一共能产生的数值为 (C7,1*C8,4+C7,3*C8,2+C7,5*C8,0)*2^3 由此可以即推得一般规律,至于Cn,i可以用杨辉三角的规律提前打表。
代码:
#include