题目链接:

Wall Painting

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

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
 
题意:
 
取k个数的异或和是多少,k从1到n;
 
思路:
 
按位计算对ans[k]的贡献,计数第i为上有多少个1和多少个0,然后算取法就好了;
 
AC代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e3+10;
const LL mod=1e6+3;
LL ans[maxn],c[maxn][maxn];
int n,a[maxn];
inline void Init()
{
memset(c,0,sizeof(c));
c[0][0]=1;
for(int i=1;i<=maxn-2;i++)
{
c[i][0]=c[i][i]=1;
for(int j=1;j<i;j++)
c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
}
}
int main()
{
Init();
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)scanf("%d",&a[i]),ans[i]=0;
LL p=1;
for(int i=0;i<=31;i++)
{
int x=0,y=0;
for(int j=1;j<=n;j++)
{
if((a[j]>>i)&1)x++;
else y++;
}
for(int j=1;j<=n;j++)
{
for(int k=1;k<=j;k+=2)
{
ans[j]=(ans[j]+c[x][k]*c[y][j-k]%mod*p)%mod;
}
}
p=2*p%mod;
}
for(int i=1;i<n;i++)printf("%lld ",ans[i]);
printf("%lld\n",ans[n]);
}
return 0;
}

  

 

hdu-4810 Wall Painting(组合数学)的更多相关文章

  1. hdu 4810 Wall Painting (组合数学+二进制)

    题目链接 下午比赛的时候没有想出来,其实就是int型的数分为30个位,然后按照位来排列枚举. 题意:求n个数里面,取i个数异或的所有组合的和,i取1~n 分析: 将n个数拆成30位2进制,由于每个二进 ...

  2. HDU 4810 Wall Painting

    Wall Painting Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. hdu 4810 Wall Painting (组合数+分类数位统计)

    Wall Painting Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  4. HDU - 4810 - Wall Painting (位运算 + 数学)

    题意: 从给出的颜料中选出天数个,第一天选一个,第二天选二个... 例如:第二天从4个中选出两个,把这两个进行异或运算(xor)计入结果 对于每一天输出所有异或的和 $\sum_{i=1}^nC_{n ...

  5. hdu 1348 Wall(凸包模板题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    M ...

  6. POJ 1113 || HDU 1348: wall(凸包问题)

    传送门: POJ:点击打开链接 HDU:点击打开链接 以下是POJ上的题: Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissio ...

  7. hdu 1348 Wall (凸包)

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  8. HDU 3685 Rotational Painting(多边形质心+凸包)(2010 Asia Hangzhou Regional Contest)

    Problem Description Josh Lyman is a gifted painter. One of his great works is a glass painting. He c ...

  9. hdu 3037 Saving Beans(组合数学)

    hdu 3037 Saving Beans 题目大意:n个数,和不大于m的情况,结果模掉p,p保证为素数. 解题思路:隔板法,C(nn+m)多选的一块保证了n个数的和小于等于m.可是n,m非常大,所以 ...

随机推荐

  1. FL2440驱动添加(3)LCD驱动添加学习笔记

    FL2440 LCD内置控制器,320*240 TFT型LCD. 自我理解总结的两种添加驱动模式: 非platform方式添加驱动: 加载驱动: 1,硬件初始化,申请内存,并作地址映射 2,分配设备号 ...

  2. git 使用笔记(二)

    续 2.15 删除文件 $ rm testDel.txt删除掉工作区的testDel.txt文件, 1)这时可以通过git checkout -- testDel.txt从版本库恢复该文件到工作区 2 ...

  3. solr 学习片段

    全文检索技术——Solr 1 主要内容 1.站内搜索技术选型 2.什么是solr Solr和lucene的区别 3.solr服务器的安装及配置 Solr整合tomcat Solr的演示 4.维护索引 ...

  4. FPSCalc——简单FPS观测类

    利用Unity做的手游项目很多时候要保证流畅度,流畅度最直观的表现就是帧率FPS.Unity编辑器模式下的帧率观测几乎没有意义,所以还是自己实现的好. 这里给一个前人写的类,我几乎原封不动,该类只有一 ...

  5. netty Failed to submit an exceptionCaught() event异常

    最近测试netty开发的服务端应用在关闭时,出现下列异常: ->###WARN#########nioEventLoopGroup-3-2###io.netty.util.internal.lo ...

  6. js 数组常用方法

    var arr =[0,1,2,3,4,5,6,7,8,9]; 1,shift() 删除数组的第一个元素,返回删除的值  //这里返回0 2,unshift(1,2)  把参数添加到数组的前面,返回值 ...

  7. Microsoft Dynamics CRM 2013 --选项集的多选

    由于从Microsoft Dynamics CRM 2011到Microsoft Dynamics CRM 2013,界面的风格发生了很大的变化 故原先在2011上开发的选项集多选在2013上面已经不 ...

  8. 响应式SharePoint模版页

    一张好的皮肤显然的会给你的项目加分不少.特别是大部分的项目,UI甚至可以决定成败. SharePoint在这方面一直都做得不好,曾经我有好多项目都是坐在美工旁边来一起修改样式.痛苦的经历. 不久以前, ...

  9. linux网络流量实时监控工具之iptraf

    这个工具还是很强大 linux网络流量实时监控工具之iptraf [我的Linux,让Linux更易用]IPTraf是一个网络监控工具,功能比nload更强大,可以监控所有的流量,IP流量,按协议分的 ...

  10. dom4j创建xml

    在前边介绍SAX,PULL等等既然能解析,当然也能生成.不过这里介绍dom4j创建xml文件,简单易懂. dom4j是独立的api,官网:http://www.dom4j.org/    可以去这下载 ...