codeforces 449D DP+容斥
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
System Crawler (2014-07-20)
Description
Jzzhu have n non-negative integers a1, a2, ..., an. We will call a sequence of indexes i1, i2, ..., ik(1 ≤ i1 < i2 < ... < ik ≤ n) a group of size k.
Jzzhu wonders, how many groups exists such that ai1 & ai2 & ... & aik = 0(1 ≤ k ≤ n)? Help him and print this number modulo1000000007(109 + 7). Operation x & y denotes bitwise AND operation of two numbers.
Input
The first line contains a single integer n(1 ≤ n ≤ 106). The second line contains n integers a1, a2, ..., an(0 ≤ ai ≤ 106).
Output
Output a single integer representing the number of required groups modulo 1000000007(109 + 7).
Sample Input
3
2 3 3
0
4
0 1 2 3
10
6
5 2 0 5 2 1
53
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; typedef __int64 LL;
const LL mod=;
const int maxn=<<;
int dp[][<<];
int a[<<]; LL pow_mod(LL a,LL b)
{
LL ret=;a%=mod;
while(b)
{
if(b&) ret=ret*a%mod;
a=a*a%mod;
b>>=;
}
return ret;
} int main()
{
int n,i,j;
int ans,t,tt;
scanf("%d",&n);
for(i=;i<=n;i++) scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)
{
if(a[i]&)
{
dp[][ a[i] ]++;dp[][ a[i]^ ]++;
}
else dp[][ a[i] ]++;
}
for(i=;i<;i++)
for(j=;j<maxn;j++)
{
t=<<(i+);
if(j&t)
{
dp[i+][j]+=dp[i][j];dp[i+][ j-t ]+=dp[i][j];
}
else dp[i+][j]+=dp[i][j];
}
ans=;
for(j=;j<maxn;j++)
{
t=;
for(i=;i<;i++)
if((<<i)&j)
t=-t;
tt=pow_mod(,dp[][j]);
tt--;
ans=((ans+t*tt)%mod+mod)%mod;
}
printf("%d\n",ans);
return ;
}
codeforces 449D DP+容斥的更多相关文章
- bzoj 3622 DP + 容斥
LINK 题意:给出n,k,有a,b两种值,a和b间互相配对,求$a>b$的配对组数-b>a的配对组数恰好等于k的情况有多少种. 思路:粗看会想这是道容斥组合题,但关键在于如何得到每个a[ ...
- 【BZOJ 4665】 4665: 小w的喜糖 (DP+容斥)
4665: 小w的喜糖 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 94 Solved: 53 Description 废话不多说,反正小w要发喜 ...
- [Luogu P1450] [HAOI2008]硬币购物 背包DP+容斥
题面 传送门:https://www.luogu.org/problemnew/show/P1450 Solution 这是一道很有意思的在背包里面做容斥的题目. 首先,我们可以很轻松地想到暴力做背包 ...
- Codeforces 611C New Year and Domino DP+容斥
"#"代表不能放骨牌的地方,"."是可以放 500*500的矩阵,q次询问 开两个dp数组,a,b,a统计横着放的方案数,b表示竖着放,然后询问时O(1)的,容 ...
- codeforces 342D Xenia and Dominoes(状压dp+容斥)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud D. Xenia and Dominoes Xenia likes puzzles ...
- Codeforces.348D.Turtles(容斥 LGV定理 DP)
题目链接 \(Description\) 给定\(n*m\)的网格,有些格子不能走.求有多少种从\((1,1)\)走到\((n,m)\)的两条不相交路径. \(n,m\leq 3000\). \(So ...
- HDU 5838 (状压DP+容斥)
Problem Mountain 题目大意 给定一张n*m的地图,由 . 和 X 组成.要求给每个点一个1~n*m的数字(每个点不同),使得编号为X的点小于其周围的点,编号为.的点至少大于一个其周围的 ...
- [BZOJ 1042] [HAOI2008] 硬币购物 【DP + 容斥】
题目链接:BZOJ - 1042 题目分析 首先 Orz Hzwer ,代码题解都是看的他的 blog. 这道题首先使用DP预处理,先求出,在不考虑每种硬币个数的限制的情况下,每个钱数有多少种拼凑方案 ...
- CF285E Positions in Permutations(dp+容斥)
题意,给定n,k,求有多少排列是的 | p[i]-i |=1 的数量为k. Solution 直接dp会有很大的后效性. 所以我们考虑固定k个数字使得它们是合法的,所以我们设dp[i][j][0/1] ...
随机推荐
- java HashMap 内存泄漏
import java.util.HashMap; import java.util.Map; public class HashMapOver { public static void main(S ...
- LiteIDE 错误: 进程无法启动
问题 运行 01_hello.go,提示以下错误 新建文件夹().exe [C:/Users/Administrator/Desktop/新建文件夹()] 错误: 进程无法启动. 原因 工程目录名不能 ...
- Maven:项目结构
目录结构图: project |- src |- main //工程源代码目录 |- java //工程java源代 ...
- 在无TNS配置时,登录到数据库。
sqlplus user/pw@ip:port/servicename sqlplus user/pwd@tnsname sqlplus user/pwd---aix sqlplus /nolog&g ...
- NSCharacterSet去除字符串中的空格、删除指定\任意字符集
一.去除首尾的空格 /** 1.去除首尾的空格*/ NSString *strMsg=@" 简书作者:CoderZb "; NSString *strResult = [strMs ...
- 在VUE中,关于CKEditor使用
官方文档 语言配置 代码如下 ClassicEditor .create( document.querySelector( '#editor' ), { language: 'de' // 配置语言 ...
- paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之onehot coding styles(index-parameter style with registered outputs)
case语句中,对于state/next 矢量仅仅做了1-bit比较. parameter 值不是表示FSM的状态编码,而是表示state/next变量的索引.
- 「新手必看」Python+Opencv实现摄像头调用RGB图像并转换成HSV模型
在ROS机器人的应用开发中,调用摄像头进行机器视觉处理是比较常见的方法,现在把利用opencv和python语言实现摄像头调用并转换成HSV模型的方法分享出来,希望能对学习ROS机器人的新手们一点帮助 ...
- MDK editions for Nuvoton devices
10 Sep 2018 MDK editions for Nuvoton devices For users of Nuvoton devices, Keil® MDK increases its a ...
- 牛客练习赛29 B
炎热的早上,gal男神们被迫再操场上列队,gal男神们本来想排列成x∗x的正方形,可是因为操场太小了(也可能是gal男神太大了),校长安排gal男神们站成多个4∗4的正方形(gal男神们可以正好分成n ...