Wall Painting

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4339    Accepted Submission(s): 1460

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


#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<algorithm>
#include<stack>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long ll;
int n;
const int mod=1e6+3;
ll a[1005];
int sum[65];
ll ans[1005];
ll C[1005][1005];
ll pow_mod(ll x,ll n,ll mod)
{
ll res=1;
while(n>0)
{
if(n%2==1)
{
res=res*x;
res=res%mod;
}
x=x*x;
x=x%mod;
n>>=1;
}
return res;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
for(int i=0;i<=1000;i++)
{
C[i][0]=1;
}
for(int i=1;i<=1000;i++)
{
for(int j=0;j<=i;j++)
C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
} //ll t1,t2;
//while(cin>>t1>>t2)cout<<C[t1][t2]<<endl;
while(~scanf("%d",&n))
{
memset(sum,0,sizeof(sum));
memset(ans,0,sizeof(ans));
for(int i=0;i<n;i++)scanf("%lld",&a[i]);
for(int i=0;i<n;i++)
{
for(int j=0;j<32;j++)
{
if((1<<j)&a[i])sum[j]++;
}
} for(int i=1;i<=n;i++)
for(int j=0;j<32;j++)
{
ll k=min(sum[j],i);
ll tot=0;
for(int kk=1;kk<=k;kk+=2)
{
tot=(tot+C[sum[j]][kk]*C[n-sum[j]][i-kk]%mod)%mod;
}
ans[i]=(ans[i]+tot*pow_mod(2,j,mod)%mod)%mod;
}
for(int i=1;i<n;i++)
printf("%lld ",ans[i]);
printf("%lld",ans[n]);
printf("\n");
}
return 0; }

hdu 4810 Wall Painting (组合数+分类数位统计)的更多相关文章

  1. HDU 4810 Wall Painting

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

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

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

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

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

  4. [ACM] ural 1057 Amount of degrees (数位统计)

    1057. Amount of Degrees Time limit: 1.0 second Memory limit: 64 MB Create a code to determine the am ...

  5. Codeforces 55D Beautiful Number (数位统计)

    把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容:  a positive integer number is beautiful if and only if it is  ...

  6. hdu-4810 Wall Painting(组合数学)

    题目链接: Wall Painting Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. 动态规划——区间DP,计数类DP,数位统计DP

    本博客部分内容参考:<算法竞赛进阶指南> 一.区间DP 划重点: 以前所学过的线性DP一般从初始状态开始,沿着阶段的扩张向某个方向递推,直至计算出目标状态. 区间DP也属于线性DP的一种, ...

  8. HDU 2089:不要62(数位DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=2089 不要62 Problem Description   杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer) ...

  9. HDU 5898:odd-even number(数位DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=5898 题意:给出一个区间[l, r],问其中数位中连续的奇数长度为偶数并且连续的偶数长度为奇数的个数.(1< ...

随机推荐

  1. Mysql数据库的优化(本文摘自于网络,文章末端有原文链接)

    对于一个以数据为中心的应用,数据库的好坏直接影响到程序的性能,因此数据库性能至关重要.一 般来说,要保证数据库的效率,要做好以下四个方面的工作: ① 数据库设计 ② sql语句优化 ③ 数据库参数配置 ...

  2. AtCoder Beginner Contest 144 题解

    传送门 $cf$ 自闭了,打 $abc$ 散散心 A - 9x9 ...这个有什么好讲的吗,题目看懂就会做了 #include<iostream> #include<cstdio&g ...

  3. 怎样发出一个HTTP请求

    需要使用 xhr.send(); 参数为请求数据体, 如果没有就传入null, 一般来说, GET请求是不用传参的, POST就视情况而定, 理论上所有GET请求都可以改为POST, 反之则不行. v ...

  4. WPf ObservableCollection异步调用问题

    当ObservableCollection列表被UI线程占用时,如果在异步线程中调用ObservableCollection,会弹出以下异常: private void Button1_OnClick ...

  5. 【php设计模式】桥接模式

    定义: 将抽象与实现分离,使它们可以独立变化.它是用组合关系代替继承关系来实现,从而降低了抽象和实现这两个可变维度的耦合度. 角色: 抽象化(Abstraction)角色:定义抽象类,并包含一个对实现 ...

  6. canvas之五角星的绘制

    <html> <head> <meta charset=utf-8> <title>绘制简单图形线及矩形</title> <style ...

  7. SQL脚本优化

    1.创建索引一.要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引   (1)在经常需要进行检索的字段上创建索引,比如要按照表字段username进行检索,那么就应 ...

  8. 原创js脚本实现百度网盘任意文件强制下载

    代码: //get file list data var data=require("system-core:context/context.js").instanceForSys ...

  9. 使用python下载图片(福利)

    刚学python 没多久, 代码处处是漏洞,也希望各位大佬理解一下 爬出来的图片... 使用的 是 https://www.tianapi.com/  接口下的 美女图片... (需要自己注册一个账号 ...

  10. linux usb驱动记录(二)

    三.usb设备的识别过程 在这里梳理一下上一篇博客中的内容:(这张图来自https://blog.csdn.net/lizuobin2/article/details/51931161) 上一篇博客刚 ...