HDU 4810 Wall Painting

Wall Painting

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


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

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6216  6215  6214  6213  6212 
 

网上说这是水题,一眼就看出来,我 觉得然并卵,作为菜鸟的我,对这种题,也a不掉,一开始想的是每次计算这一层的时候利用上一层的结果,gg,超时,,,,

然后事后看了看他们的博客,才想起来对每一位进行处理,看看这一位中含有多少个1,在看看你需要选出来,用组合数来解

然后枚举1的个数为奇数的情况,注意个数不能大于n和天数,以及选0的个数也不能大于天数。

来个例子把

比如实例

1 2 10 1

化成二进制就是

8 4 2 1

=======================

0 0 0 1

0 0 1 0

1  0  1 0

0  0  0  1

===========================

比如第四位,只含有一个1,如果我们选一种颜料的时候,选择方案在这一位上的表现就是 那么出0,要么出1,很明显,出0的时候,对结果值,无贡献,只有出来1的时候,出来一的情况下对结果有贡献,然后出来1有C(1,1) 个,乘起来就好啦

My ugly code

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#define ll long long

using namespace std;
const int mod=1e6+3;
int n,a[1010];
int c[1005][1005];
int cnt[35];

int main(){

    /*组合数打表*/
    memset(c,0,sizeof(c));
    c[0][0]=1;
    for(int i=1;i<=1000;i++){
        for(int j=0;j<=i;j++){
            if(j==0 || j==i) c[i][j]=1;
            else c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
        }
    }

    while(~scanf("%d",&n)){
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            /*统计输入的每一个数的每一位*/
            for(int j=0;j<=31;j++) {
                if((a[i]>>j)&1) cnt[j]++;
            }
        }
        ll ans[1010];
        /*三层循环,最里面那个是出来1-i个1*/
        for(int i=1;i<=n;i++){
            ans[i]=0;
            for(int j=0;j<=31;j++){
                for(int k=1;k<=cnt[j] && k <= i;k+=2){
                        /*这里为什么这么写,体会下,对每一位处理*/
                    ans[i]=(ans[i]+(ll)(1<<j)%mod*(ll)c[cnt[j]][k]%mod*(ll)c[n-cnt[j]][i-k]%mod)%mod;
                }
                ans[i]%=mod;
            }
        }
        printf("%I64d",ans[1]);
        for(int i=2;i<=n;i++)
            printf(" %I64d",ans[i]);
        printf("\n");
    }


    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值