Wall Painting
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2902 Accepted Submission(s): 940
Problem Description
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
Sample Output
Source
2013ACM/ICPC亚洲区南京站现场赛——题目重现
题意:
给出n个数字,代表不同的颜色染料
第一天取一种染料,第二天取两种染料,,,,第n天取n种染料
第x天就要取x种染料异或(混合)得到新的染料 y
求解第x天有几种方式,将所有方式的 y 相加得到的就是答案
题解:
因为n太大,不能进行简单的容斥原理,需要找规律
将样例给的数字分解成二进制:
1: 0 0 0 1
2: 0 0 1 0
10: 1 0 1 0
1: 0 0 0 1
第二天的时候;
因为两个数字异或值==两个数字化为二进制各个位置异或和
第一位c【1】【1】*c【3】【1】*(1<<3)==24
第二位c【0】【1】*c【3】【1】*(1<<2)==0
第三位c【2】【1】*c【2】【1】*(1<<1)==8
第四位c【2】【1】*c【2】【1】*(1<<0)==4
总和为36
由此可求得其他答案
杨辉三角来打表组合数
#define NUM 1005
LL c[NUM][NUM];
void init()
{
c[0][0]=c[1][0]=c[1][1]=1;
for(int i=2;i
#include
#include
#include
using namespace std;
#define MAXN 3000
#define mod 1000003
#define LL long long
LL n,pos;
int graph[MAXN][40];
#define NUM 1005
LL c[NUM][NUM];
void init()
{
c[0][0]=c[1][0]=c[1][1]=1;
for(int i=2;i=0&&i-j<=t0){
LL temp=(1<