hdu 4810 Wall Painting (组合数学+二进制)
下午比赛的时候没有想出来,其实就是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 (组合数学+二进制)的更多相关文章
- HDU 4810 Wall Painting
Wall Painting Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 4810 Wall Painting (组合数+分类数位统计)
Wall Painting Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU - 4810 - Wall Painting (位运算 + 数学)
题意: 从给出的颜料中选出天数个,第一天选一个,第二天选二个... 例如:第二天从4个中选出两个,把这两个进行异或运算(xor)计入结果 对于每一天输出所有异或的和 $\sum_{i=1}^nC_{n ...
- hdu-4810 Wall Painting(组合数学)
题目链接: Wall Painting Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 1348 Wall(凸包模板题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others) M ...
- POJ 1113 || HDU 1348: wall(凸包问题)
传送门: POJ:点击打开链接 HDU:点击打开链接 以下是POJ上的题: Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- Hdu 4810
2014-05-02 15:53:50 题目连接 2013年南京现场赛的题目,现场的时候,排在我们前面的队伍基本都过了这题,我们后面的队伍也有不少过了这题,唯独我们没有.. 后来是Qingyu Sha ...
- hdu 1348 Wall (凸包)
Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 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 ...
随机推荐
- HOWTO: Create native-looking iPhone/iPad applications from HTML, CSS and JavaScript
HOWTO: Create native-looking iPhone/iPad applications from HTML, CSS and JavaScript Though it's not ...
- [翻译]Kafka Streams简介: 让流处理变得更简单
Introducing Kafka Streams: Stream Processing Made Simple 这是Jay Kreps在三月写的一篇文章,用来介绍Kafka Streams.当时Ka ...
- SWF Web播放器
<HTML> <HEAD> <!-- saved from url=(0013)about:internet --> <TITLE> Untitled. ...
- rdtsc获取时间统计程序的运行效率
__u64 rdtsc() { __u32 lo,hi; __asm__ __volatile__ ( "rdtsc&q ...
- Selenium中expected_conditions下text_to_be_present_in_element_value方法的使用
text_to_be_present_in_element: 判断某个元素中的text是否包含了预期的字符串 text_to_be_present_in_element_value: 判断某个元素中的 ...
- ZOJ3724 Delivery(树状数组??)
题意:给你一个有向图,第一类边是从第i个点到第i+1个点的,还有多出来的m条二类边,是从u到v的,同样是有向的.然后你要处理询问,从u到v经过最多一次二类边的最短距离是多少. 题目我觉得是神题,然后看 ...
- iOS-CALayer遮罩效果
self.view.backgroundColor = [UIColor blackColor]; , , , ); self.imageLayer.contents = (__ ...
- Windows命令查看文件MD5
certutil -hashfile filename MD5 certutil -hashfile filename SHA1 certutil -hashfile filename SHA256
- 安装mysql之后,存入中文出现乱码
如图显示:安装mysql之后,存入中文出现乱码 解决方案: 找到如图的文件位置 打开进行如图的修改: 结果:
- Java中常用的加密方法(JDK)
加密,是以某种特殊的算法改变原有的信息数据,使得未授权的用户即使获得了已加密的信息,但因不知解密的方法,仍然无法了解信息的内容.大体上分为双向加密和单向加密,而双向加密又分为对称加密和非对称加密(有些 ...