HDU 4810 wall painting

Source: Internet
Author: User

Wall Painting Time Limit: 10000/5000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1265 accepted submission (s): 360


Problem descriptionms. 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 shoshould tell mr. Fang the answer from the first day to the n-th day.
Inputthere 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.
Outputfor 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
41 2 10 1
 
Sample output
14 36 30 8
 
Source2013acm/ICPC Nanjing site competition-reproduction of questions


Question and code:


When I got the question, I was always thinking about a combination of methods, or DP and so on, which could be deduced from two numbers to three numbers. I had no idea after I thought about it for a while.

Then we think of the nature of the exclusive or, because the final answer is to be added, so if every bit after the exclusive or wants to have a value, therefore, we must ensure that the number of The number in the current bit for the XOR operation must be an odd number. When we think of this, we will have the idea. We only need to find the number of 1 and 0 digits for each digit in the case of a binary number, then we can find the number of combinations.

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;const long long mod=1e6+3;long long  C[1010][1010];long long l[70],r[70];long long num[70];long long sum=0;void init(){    C[0][0]=1;    C[1][0]=C[1][1]=1;C[1][2]=0;    for(int i=2;i<=1000;i++)    {        C[i][0]=1;        for(int j=1;j<=i;j++)            C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;        C[i][i+1]=0;    }    num[0]=1;num[1]=2;    for(int i=2;i<=62;i++)    {       num[i]=(num[i-1]*2)%mod;    }}int main(){    init();    int n,color,k;    while(scanf("%d",&n)!=EOF)    {        sum=0;        memset(l,0,sizeof(l));        for(int i=1;i<=n;i++)        {            scanf("%d",&color);            sum+=color;            sum%=mod;            k=0;            while(color)            {                l[k++]+=(color&1);                color/=2;            }        }        printf("%I64d",sum);        for(int i=0;i<=62;i++)        {            r[i]=n-l[i];        }        for(int i=2;i<=n;i++)        {            sum=0;            for(int j=0;j<=62;j++)            {                if(l[j])                for(k=1;k<=i&&k<=l[j];k+=2)                {                    //printf("%d %d %d,%d %d %d,%d  \n",l[j],k,C[l[j]][k],r[j],n-k,C[r[j]][n-k],num[j]);                   sum+=(C[l[j]][k]*C[r[j]][i-k]%mod*num[j])%mod;                   sum%=mod;                }            }            printf(" %I64d",sum);        }        puts("");    }    return 0;}





HDU 4810 wall painting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.