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] ...
随机推荐
- DateTime与long互转
DateTime转long: public static long GetDateLong(object time) { DateTime epoc = TimeZone.CurrentTimeZon ...
- OAuth认证协议中的HMACSHA1加密算法
<?php function hmacsha1($key,$data) { $blocksize=64; $hashfunc='sha1'; if (strlen($key)>$block ...
- Python9-网络编程4-day33
解决黏包问题: 在传输大量数据之前,先告诉接收端要发送数据大小 如果想更漂亮的解决问题,可以通过struct模块来定制协议为什么会出现黏包现象: 首先只有在tcp协议中才会出现黏包现象 是因为tcp协 ...
- python3中urllib库的request模块详解
刚刚接触爬虫,基础的东西得时时回顾才行,这么全面的帖子无论如何也得厚着脸皮转过来啊! 原帖地址:https://www.2cto.com/kf/201801/714859.html 什么是 Urlli ...
- pandas-Notes1
#coding = utf-8 import pandas as pd import numpy as np import matplotlib as plt # series, like vecto ...
- Mac中文乱码问题
在终端切换到文档所在的目录,输入下面的命令: iconv -c -f GB2312 -t UTF-8 乱码的文件名 >> 新文件的名称
- 使用fio测试磁盘I/O性能
简介: fio是测试IOPS的非常好的工具,用来对硬件进行压力测试和验证,支持13种不同的I/O引擎,包括:sync,mmap, libaio, posixaio, SG v3, splice, nu ...
- SPOJ375 Query on a tree(树链剖分)
传送门 题意 给出一棵树,每条边都有权值,有两种操作: 把第p条边的权值改为x 询问x,y路径上的权值最大的边 code #include<cstdio> #include<algo ...
- HDU 3667 费用流 拆边 Transportation
题意: 有N个城市,M条有向道路,要从1号城市运送K个货物到N号城市. 每条有向道路<u, v>运送费用和运送量的平方成正比,系数为ai 而且每条路最多运送Ci个货物,求最小费用. 分析: ...
- Selenium WebDriver-actionchain模拟键盘左键长按
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...