HDU 4810 Wall Painting(组合数学 + 位运算)——2013ACM/ICPC亚洲区南京站现场赛

传送门

Wall Painting

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2627    Accepted Submission(s): 839

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 <= 103).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 106 +3) from the first day to the n-th day.
 

Sample Input
4
1 2 10 1
 

Sample Output
14 36 30 8

题目大意:

给定 n 个数,求任意 ni=1C(n,i) 个数的异或和。

解题思路:

首先将每个数的2进制求出来,在每位2进制数中求出 1 的个数,拿样例来讲吧。

1  =  0   0   0   1
2  =  0   0   1   0
10=  1   0   1   0
1  =  0   0   0   1

每次选奇数个 1 和 剩余的选的个数⑴ 个 0, 比如说求任意两个数的异或和,那末我们选 11 ,选 210, 我们肯定选

奇数个 1, 由于偶数个 1 异或还是 0 没成心义,然后就是组合数了, 从当前的 1 的总个数里面选择奇数个 1 ,在乘以相应的 2x

次幂,(c[cnt[j]][k]c[(ncnt[j])][ik])(2j)其中 cnt[j] 表示的是第 j1 的总个数, k 表示的是要选择的 1 的个数。i 表示的

是任意 i 个数异或。。。大体上看看代码就好懂了。

My Code

/**
2016 - 09 - 20 晚上
Author: ITAK
Motto:

本日的我要超出昨日的我,明日的我要胜过本日的我,
以创作出更好的代码为目标,不断地超出自己。
**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e3+5;
const int MOD = 1e6+3;
const double eps = 1e⑺;
const double PI = acos(-1);
using namespace std;

int Scan_Int()///输入外挂
{
int res = 0, ch, flag = 0;
if((ch=getchar()) == '-')
flag = 1;
else if(ch >= '0' && ch<='9')
res = ch-'0';
while((ch=getchar())>='0' && ch<='9')
res = res*10+ch-'0';
return flag?-res:res;
}
LL Scan_LL()///输入外挂
{
LL res=0,ch,flag=0;
if((ch=getchar())=='-')
flag=1;
else if(ch>='0'&&ch<='9')
res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')
res=res*10+ch-'0';
return flag?-res:res;
}

void Out(int a)///输出外挂
{
if(a>9)
Out(a/10);
putchar(a%10+'0');
}
LL c[MAXN][MAXN];
void Init()
{
c[0][0] = 1;
for(int i=1; i<MAXN; i++)
c[i][0] = 1;
for(int i=1; i<MAXN; i++)
for(int j=1; j<MAXN; j++)
c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD;
}
LL a[MAXN];
int cnt[70];
int main()
{
Init();
int n;
while(~scanf("%d",&n))
{
for(int i=0; i<n; i++)
scanf("%I64d",&a[i]);
memset(cnt, 0, sizeof(cnt));
for(int i=0; i<n; i++)
{
LL tp = a[i];
for(int j=0; j<63; j++)
{
if(tp & 1)
cnt[j]++;
tp>>=1;
}
}
for(int i=1; i<=n; i++)
{
LL sum = 0;
for(int j=0; j<63; j++)
{
if(cnt[j])
{
for(int k=1; k<=i; k+=2)
{
if(cnt[j]>=k && (n-cnt[j]>=i-k))
{
sum += ((c[cnt[j]][k]*c[(n-cnt[j])][i-k]%MOD)*(1LL<<j)%MOD);
sum %= MOD;
}
}
}
}
if(i != n)
cout<<sum<<" ";
else
cout<<sum<<endl;
}
}
return 0;
}

波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » HDU 4810 Wall Painting(组合数学 + 位运算)——2013ACM/ICPC亚洲区南京站现场赛

发表评论

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡