国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

[HDU 4810] Wall Painting 組合數(shù) 按位處理

2019-11-08 18:28:54
字體:
供稿:網(wǎng)友

Wall Painting

Time Limit: 5000ms Memory Limit: 32MB

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 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.

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個數(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)為C(N?j,i?j)?C(cnt[K],j)?2k?1 然后就發(fā)現(xiàn)時間復(fù)雜度為O(N2)加上一個32的常數(shù)還有多組測試數(shù)據(jù),5秒有點懸啊 別管那么多啦反正大力出奇跡就對啦0.0

代碼

#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <climits>typedef long long LL;const int MAXN = 1100;const int MOD = 1000003;LL C[MAXN][MAXN];int nums[MAXN];int sum[40];int main () { C[0][0] = 1; for(int i = 1; i<1100; i++) for(int j = 1; j<1100; j++) C[i][j] = (C[i-1][j-1]+C[i-1][j]) % MOD; C[0][0] = 0; int n; while(~scanf("%d", &n)) { memset(sum, 0, sizeof sum); for(int i = 1; i<=n; i++) scanf("%d", &nums[i]); for(int i = 1; i<=n; i++) for(int j = 1; j<=31; j++) sum[j] += ((nums[i] & (1<<(j-1)))!=0); LL ans = 0; for(int i = 1; i<=n; i++) { ans = 0; for(int k = 1; k <= 31; k++) for(int j = 1; j<=sum[k] && j <= i; j+=2) ans += (LL)(1LL<<((LL)k-1LL))%MOD*(LL)C[sum[k]+1][j+1]%MOD * C[n-sum[k]+1][i-j+1] % MOD, ans %= MOD; printf("%I64d%c", ans, i == n ? '/n' : ' '); } }}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 白河县| 仁寿县| 棋牌| 临清市| 凤山县| 密云县| 寿光市| 波密县| 泰安市| 武安市| 滦南县| 贞丰县| 杨浦区| 大方县| 永和县| 桃园市| 昭通市| 东乡县| 乃东县| 晋中市| 绥中县| 湖口县| 巨野县| 雷山县| 九龙县| 广安市| 公主岭市| 富裕县| 海原县| 宜章县| 宿松县| 嘉义市| 竹山县| 河北省| 昭苏县| 辽中县| 桦甸市| 顺义区| 铜梁县| 宁明县| 东阳市|