题目链接

下午比赛的时候没有想出来,其实就是int型的数分为30个位,然后按照位来排列枚举。

题意:求n个数里面,取i个数异或的所有组合的和,i取1~n

分析:

将n个数拆成30位2进制,由于每个二进制位异或后相加和原来的数异或相加是一样的,所以只需要对每一位累加计算,用组合数学取数就行了,奇数个异或得1,偶数个异或得0,再乘以自己的二进制位值,复杂度O(30*n*n)

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <cstring>
#include <map>
#include <cstdlib>
#include <algorithm>
#define LL __int64
#define INF 0x3f3f3f3f
const int maxn = +;
const int mo = +;
using namespace std;
LL c[maxn][maxn], a[], p[]; //注意要用LL,中间计算会超int
void init()
{
int i, j;
memset(c, , sizeof(c));
for(i = ; i < maxn-; i++)
c[i][i] = c[i][] = ;
for(i = ; i < maxn-; i++)
for(j = ; j < i; j++)
c[i][j] = (c[i-][j-] + c[i-][j])%mo; p[] = ;
for(i = ; i < ; i++)
p[i] = (*p[i-])%mo;
}
void cal(int x)
{
int cnt = ;
while(x)
{
if(x%)
a[cnt] ++;
x /= ;
cnt ++; //这个不要放到上面数组中,不然会在数组的下标多加一个
}
}
int main()
{
int n, i, j, k, x;
LL tmp, ans;
init();
while(~scanf("%d", &n))
{
memset(a, , sizeof(a));
for(i = ; i < n; i++)
{
scanf("%d", &x);
cal(x);
}
for(i = ; i <= n; i++)
{
ans = ;
for(j = ; j < ; j++)
{
for(k = ; k <= i; k += )
{
tmp = ((LL)(p[j]*c[a[j]][k]*c[n-a[j]][i-k]))%mo; //该位的数值 * 该位为1的个数选奇数个 * 为0的个数选空着的个数。
ans += tmp;
ans %= mo;
}
}
if(i == n)
printf("%I64d\n", ans);
else
printf("%I64d ", ans);
}
}
return ;
}

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 (组合数+分类数位统计)

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

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

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

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

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

  5. hdu 1348 Wall(凸包模板题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    M ...

  6. POJ 1113 || HDU 1348: wall(凸包问题)

    传送门: POJ:点击打开链接 HDU:点击打开链接 以下是POJ上的题: Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissio ...

  7. Hdu 4810

    2014-05-02 15:53:50 题目连接 2013年南京现场赛的题目,现场的时候,排在我们前面的队伍基本都过了这题,我们后面的队伍也有不少过了这题,唯独我们没有.. 后来是Qingyu Sha ...

  8. hdu 1348 Wall (凸包)

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. HDU 3685 Rotational Painting(多边形质心+凸包)(2010 Asia Hangzhou Regional Contest)

    Problem Description Josh Lyman is a gifted painter. One of his great works is a glass painting. He c ...

随机推荐

  1. nginx+php+flight 构建RESTFul API

    配置: Nginx: conf目录下nginx.conf配置文件. 第44行改为:root   D:/wwwroot/www; 第45行改为:index  index.html index.htm i ...

  2. Core Data数据库迁移

    一. Lightweight Migration i. 适合场景 Simple addition of a new attribute Removal of an attribute A non-op ...

  3. C#单链表(数据结构)

    学习单链表的源码项目:http://files.cnblogs.com/xmfdsh/CSharp%E5%8D%95%E9%93%BE%E8%A1%A8.rar 链表是用一组任意的存储单元来存储线性表 ...

  4. POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...

  5. App自适应

    http://blog.csdn.net/newjueqi/article/details/42779221

  6. OneApm,NewRelic

    https://newrelic.com/ http://www.csdn.net/article/2013-03-25/2814631-new-relic-mobile-app-real-time- ...

  7. ExtJs之Ext.each

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  8. spring 主题使用详解[转]

    在common_include_v2.jsp文件中,spring主题的使用: <link href="${staticPath }/<spring:theme code='sty ...

  9. 内存分析_.Net内存原理介绍

    内存原理介绍 1.       .Net应用程序中的内存 1.1.Net内存类型 Windows使用一个系统:虚拟寻址系统.这个系统的作用是将程序可用的内存地址映射到硬件内存中的实际地址上.其实际结果 ...

  10. mq_getattr

    NAME mq_getattr - 获取消息队列的属性(REALTIME) SYNOPSIS #include <mqueue.h> int mq_getattr(mqd_t mqdes, ...