hdu 4810 Wall Painting
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 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 colZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vciAyLCAxLCAyLiBTaGUgY2FuIGdldCBjb2xvciAzLCAzLCAwIHdpdGggMyBkaWZmZXJlbnQgcGxhbnMuIEluIHRoaXMgaW5zdGFuY2UsIHRoZSBhbnN3ZXIgTXIuRmFuZyB3YW50cyB0byBnZXQgb24gdGhlIHNlY29uZCBkYXkgaXMgMyAmIzQzOyAzICYjNDM7IDAgPSA2Ljxicj4KTXIuRmFuZyBpcyBzbyBidXN5IHRoYXQgaGUgZG9lc26hr3Qgd2FudCB0byBzcGVuZCB0b28gbXVjaCB0aW1lIG9uIGl0LiBDYW4geW91IGhlbHAgaGltPzxicj4KWW91IHNob3VsZCB0ZWxsIE1yLkZhbmcgdGhlIGFuc3dlciBmcm9tIHRoZSBmaXJzdCBkYXkgdG8gdGhlIG4tdGggZGF5LgoKIAo8YnI+CgpJbnB1dAoKVGhlcmUgYXJlIHNldmVyYWwgdGVzdCBjYXNlcywgcGxlYXNlIHByb2Nlc3MgdGlsbCBFT0YuPGJyPgpGb3IgZWFjaCB0ZXN0IGNhc2UsIHRoZSBmaXJzdCBsaW5lIGNvbnRhaW5zIGEgc2luZ2xlIGludGVnZXIgTigxIDw9IE4gPD0gMTA8c3VwPjM8L3N1cD4pLlRoZSBzZWNvbmQgbGluZSBjb250YWlucyBOIGludGVnZXJzLiBUaGUgaS10aCBpbnRlZ2VyIHJlcHJlc2VudHMgdGhlIGNvbG9yIG9mIHRoZSBwaWdtZW50cyBpbiB0aGUgaS10aCBiYWcuCgogCjxicj4KCk91dHB1dAoKRm9yIGVhY2ggdGVzdCBjYXNlLCBvdXRwdXQgTiBpbnRlZ2VycyBpbiBhIGxpbmUgcmVwcmVzZW50aW5nIHRoZSBhbnN3ZXJzKG1vZCAxMDxzdXA+Njwvc3VwPiAmIzQzOzMpIGZyb20gdGhlIGZpcnN0IGRheSB0byB0aGUgbi10aCBkYXkuCgogCjxicj4KClNhbXBsZSBJbnB1dAoKPHByZSBjbGFzcz0="brush:java;">4
1 2 10 1
Sample Output
14 36 30 8
Source
2013ACM/ICPC亞洲區南京站現場賽——題目重現
題解及代碼:
拿到題目的時候一直在想有什麼組合的方法,或者是DP之類的可以由兩個數推導到三個數等等,想了好一會也沒什麼思路。
之後想到異或的性質,因為最後的答案是要相加的,所以異或之後的每一位想要有值的話,那麼我們必須保證進行異或的數字在當前位上的1個個數必須是奇數,想到這裡,思路就有了。我們只需要求出每個數二進制表示形勢下每一位1和0的個數,那麼然後在求組合數就可以了。
#include
#include
#include
#include
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;
}