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

Ms. Fang每天从不同的颜料袋中选择特定数量的颜料,通过混合获得独特的颜色来绘制她的Great Funny Wall。她的丈夫Mr. Fang想知道,在第K天,如果Ms. Fang选择了K个不同颜料袋,所有可能的颜色组合之和是多少。这个问题涉及到组合数学和模运算,需要高效地计算从第一天到最后一天的所有答案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;

}




 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值