hdu-4810 Wall Painting(组合数学)
题目链接:
Wall Painting
Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2681    Accepted Submission(s): 857
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.
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.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e3+10;
const LL mod=1e6+3;
LL ans[maxn],c[maxn][maxn];
int n,a[maxn];
inline void Init()
{
memset(c,0,sizeof(c));
c[0][0]=1;
for(int i=1;i<=maxn-2;i++)
{
c[i][0]=c[i][i]=1;
for(int j=1;j<i;j++)
c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
}
}
int main()
{
Init();
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)scanf("%d",&a[i]),ans[i]=0;
LL p=1;
for(int i=0;i<=31;i++)
{
int x=0,y=0;
for(int j=1;j<=n;j++)
{
if((a[j]>>i)&1)x++;
else y++;
}
for(int j=1;j<=n;j++)
{
for(int k=1;k<=j;k+=2)
{
ans[j]=(ans[j]+c[x][k]*c[y][j-k]%mod*p)%mod;
}
}
p=2*p%mod;
}
for(int i=1;i<n;i++)printf("%lld ",ans[i]);
printf("%lld\n",ans[n]);
}
return 0;
}
hdu-4810 Wall Painting(组合数学)的更多相关文章
- hdu 4810 Wall Painting (组合数学+二进制)
		
题目链接 下午比赛的时候没有想出来,其实就是int型的数分为30个位,然后按照位来排列枚举. 题意:求n个数里面,取i个数异或的所有组合的和,i取1~n 分析: 将n个数拆成30位2进制,由于每个二进 ...
 - 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 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 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 ...
 - hdu 3037 Saving Beans(组合数学)
		
hdu 3037 Saving Beans 题目大意:n个数,和不大于m的情况,结果模掉p,p保证为素数. 解题思路:隔板法,C(nn+m)多选的一块保证了n个数的和小于等于m.可是n,m非常大,所以 ...
 
随机推荐
- GWYAlertSelectView 选择收货地址和选择联系人
			
iOS 开发在app内(特别是在类似购物和旅游类)经常会用到选择,添加联系人和收货地址,而且经常都是在跳转界面,很是麻烦,今天我就自己封装了一个类似弹出视图的代码,方便了很多!demo地址: http ...
 - Java final static abstract关键字介绍
			
一,抽象类:abstract 1,只要有一个或一个以上抽象方法的类,必须用abstract声明为抽象类; 2,抽象类中可以有具体的实现方法; 3,抽象类中可以没有抽象方法; 4,抽象类中的抽象方法必须 ...
 - [Design Pattern] Substitute Interface
			
[Design Pattern] Substitute Interface 目的 将对象的成员建立为替身接口的成员,用来解耦对象之间的循环相依. 情景 假设开发人员接手一个系统,在系统里有订单对象.送 ...
 - Android 首页图片轮播
			
1.网络上的的一个框架,已经在github 上开源 github : https://github.com/gcgongchao/flashview 相关博客 : http://www.eoeand ...
 - Struts2--Helloworld
			
搭建Struts2环境时,我们一般需要做以下几个步骤的工作: 1.找到开发Struts2应用需要使用到的jar文件. 2.创建Web工程 3.在web.xml中加入Struts2 MVC框架启动配置 ...
 - Java从零开始学四十七(注解简述)
			
一.Java中注解Annotation 什么是注解:用来描述数据的数据(元数据). Java代码里的特殊标记.它为代码中添加用Java程序无法表达的额外信息提供一种形式化的方法,使用我们可以在未来的某 ...
 - 斯坦福iOS7公开课10笔记及演示Demo
			
这一节主要介绍了多线程中的串行队列以及滚动视图UIScrollView. 1 .多线程 这一节只是简单介绍了多线程的串行队列,即把任务加入线程队列后按顺序逐步执行. (1)目前iOS多线程提供的方法主 ...
 - 关于bitcode~
			
最近在做语音识别- 在真机调试的时候一直报 ld: '/Users/Chenglijuan/Documents/语音识别/lib/iflyMSC.framework/iflyMSC(IFlyRecog ...
 - iOS开发网络篇—NSURLConnection基本使用(二)
			
1.常用的类 NSURL:请求地址 NSURLRequest:一个NSURLRequest对象就代表一个请求,它包含的信息有: 一个NSURL对象 请求方法.请求头.请 ...
 - ubuntu15.10 给解压版的eclipse安装桌面快捷方式
			
在桌面用vi 建立eclipse.desktop文件,并赋予权限 sudo chmod u+x /home/liujl/Desktop/eclipse.desktop [Desktop Entry ...