Time Limit: 5000ms Memory Limit: 32MB
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 C(N,K) 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.
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.
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.
4 1 2 10 1
14 36 30 8
給N個數(shù),對所有1<=i<=N,求從N個數(shù)中選擇i個數(shù)異或起來的所有方案異或值累和。
很少做數(shù)學(xué)題,寒假回來神犇就送了五道數(shù)論要求一次AC的考試大禮包,果斷爆0。 感覺數(shù)學(xué)太差了,所以寫點數(shù)學(xué)的博客。。。。
考慮選i個的情況,首先發(fā)現(xiàn)如果要異或的話,二進(jìn)制下單個數(shù)位位之間不影響,可以對二進(jìn)制每一位分別考慮,問題就簡單多了。 考慮第K位,加入N個數(shù)中第K位為1的數(shù)有cnt[K]個,因為第K位為零的數(shù)不產(chǎn)生任何影響,第K位為一的數(shù)選中個數(shù)為奇數(shù)個才不為0,所以枚舉選取第K位為一的數(shù)j個,j=1,3,5….(j<=cnt[K] && j<=i)。 這種情況下 選擇第K位為零的數(shù)的方案數(shù)為C(N-j, i-j) 選擇第K位為一的數(shù)的方案數(shù)為C(cnt[K], j) 那么總方案數(shù)就是他們的乘積,對sum的貢獻(xiàn)為
新聞熱點
疑難解答