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] ...
随机推荐
- c++ json字符串转换成map管理
在cocos2dx for lua中,我们经常通过lua的table传入c++使用,然后早c++层操作数据. 实现步骤大致如下: table->string->c++层->通过rap ...
- Where art thou-freecodecamp算法题目
Where art thou 1.要求 写一个 function,它遍历一个对象数组(第一个参数)并返回一个包含相匹配的属性-值对(第二个参数)的所有对象的数组. 如果返回的数组中包含 source ...
- #ifdef #else #endif #fi #ifndef 的用法
预处理就是在进行编译的第一遍词法扫描和语法分析之前所作的工作.说白了,就是对源文件进行编译前,先对预处理部分进行处理,然后对处理后的代码进行编译.这样做的好处是,经过处理后的代码,将会变的很精短. ...
- JQuery图片轮播实例
HTML+CSS代码: <!doctype html> <html> <head> <meta charset="utf-8"> & ...
- 【Git版本控制】git将单个文件回退到某一版本
暂定此文件为a.jsp 1.进入到a.jsp所在目录,通过 git log a.jsp查看a.jsp的更改记录 2.找到想要回退的版本号:例如 fcd2093 通过 git reset fcd2 ...
- Ubuntu 18.04 下用命令行安装Sublime
介绍: 添加来源: $ wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add - $ sud ...
- 03IO端口寻址和访问控制方式
1. I/O端口和寻址 CPU 为了访问 I/O 接口控制器或者控制卡上的数据和状态信息,需要首先指定他们的地址.这种地址就称为I/O端口地址或简称端口.通常一个 I/O 控制器包含访问数据的数据端口 ...
- python3 发邮件 smtplib & email 库
嗨 实现了用163发送到qq的功能,遗留了两个问题: 1. 接收者list会报错:update:因为list[]会传递过去一个真的[]list,改成如下就可以了: before: maillist=[ ...
- manjaro kde netease-cloud-music 网易云音乐
- redis集群监控之Redis-monitor部
为了对以后有可能面临的redis集群监控做准备,这两天在准备这方面的事情,现在将其中的过程记录一下. 首先是“Ronney-Hua”的这篇文章对三中开源监控软件做了对比 文章地址:https://bl ...