http://codeforces.com/problemset/problem/449/D

题意:给n个数,求and起来最后为0的集合方案数有多少

思路:考虑容斥,ans=(-1)^k*num(k),num(k)代表至少有k个数字and起来为1的方案数,那么怎么求num呢?

考虑and起来至少为x的方案数:那么一定是2^y-1,其中y代表有多少个数&x==x,问题就变成有多少数"包含"了某个数(二进制下),用dp解决这个问题:如果某一位数字是1,那么它一定能转移到它不是1的那个位置。

即:f[i]+=f[i|(1<<j)]

注意循环,如果两层的循环换一下位置就会重复计数了。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
const ll Mod=;
ll f[],bin[];
int n;
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
void solve(){
for (int j=;j<;j++)
for (int i=;i<=;i++)
if ((<<j)&i) (f[i^(<<j)]+=f[i])%=Mod;
ll ans=;
for (int i=;i<=;i++){
int cnt=;
for (int j=;j<;j++)
if ((<<j)&i) cnt=-cnt;
ans=((ans+(cnt*(bin[f[i]]-)%Mod))%Mod+Mod)%Mod;
}
printf("%I64d\n",ans);
}
int main(){
n=read();
bin[]=;
for (int i=;i<=;i++) bin[i]=(bin[i-]*)%Mod;
for (int i=;i<=n;i++) f[read()]++;
solve();
}

Codeforces 449D Jzzhu and Numbers的更多相关文章

  1. Codeforces 449D Jzzhu and Numbers(高维前缀和)

    [题目链接] http://codeforces.com/problemset/problem/449/D [题目大意] 给出一些数字,问其选出一些数字作or为0的方案数有多少 [题解] 题目等价于给 ...

  2. Codeforces.449D.Jzzhu and Numbers(容斥 高维前缀和)

    题目链接 \(Description\) 给定\(n\)个正整数\(a_i\).求有多少个子序列\(a_{i_1},a_{i_2},...,a_{i_k}\),满足\(a_{i_1},a_{i_2}, ...

  3. Codeforces Round #257 (Div. 1) D - Jzzhu and Numbers 容斥原理 + SOS dp

    D - Jzzhu and Numbers 这个容斥没想出来... 我好菜啊.. f[ S ] 表示若干个数 & 的值 & S == S得 方案数, 然后用这个去容斥. 求f[ S ] ...

  4. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

  5. CodeForces 450B Jzzhu and Sequences (矩阵优化)

    CodeForces 450B Jzzhu and Sequences (矩阵优化) Description Jzzhu has invented a kind of sequences, they ...

  6. codeforces 449D DP+容斥

    Jzzhu and Numbers Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

  7. Jzzhu and Numbers

    Jzzhu and Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. Codeforces C. Jzzhu and Cities(dijkstra最短路)

    题目描述: Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. Jzzhu and Numbers CodeForces - 449D (高维前缀和,容斥)

    大意: 给定集合a, 求a的按位与和等于0的非空子集数. 首先由容斥可以得到 $ans = \sum \limits_{0\le x <2^{20}} (-1)^{\alpha} f_x$, 其 ...

随机推荐

  1. java并发4-单例设计方法

    单例的设计方式: 第一种:非延迟加载单例类 public class Singleton { private Singleton() {} private static final Singleton ...

  2. Android AlertDialog全屏显示去除白色边框

    使用styles.xml风格: Style.xml代码 <style name="FullScreenDialog" parent="android:style/T ...

  3. Android中的PopupWindow的使用

    PopupWindow 需要一个自定义的布局文件 列如:popupwindow.xml <?xml version="1.0" encoding="utf-8&qu ...

  4. HDU_1010——小狗走迷宫DFS

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  5. memcached学习——常用命令+基于java客户端的3种简单实现(二)

    常用命令: memcached设计的原则就是简单,所以支持的命令也不是特别多~ 1.查看memcached的状态,主要用于分析内存的使用状况.优化内存分配等 stats 查看memcached的运行状 ...

  6. PHP发送POST请求的三种方式

    class Request{ public static function post($url, $post_data = '', $timeout = 5){//curl $ch = curl_in ...

  7. nexus5 root教程

    转载自: http://www.inexus.co/article-1280-1.html http://www.pc6.com/edu/71016.html https://download.cha ...

  8. [React Testing] Reusing test boilerplate

    Setting up a shallow renderer for each test can be redundant, especially when trying to write simila ...

  9. 如何让asp.net mvc 直接运行mobile页面

    在controller里面加上下面一句 HttpContext.SetOverriddenBrowser(BrowserOverride.Mobile);

  10. CCArray(转)

    http://blog.csdn.net/passtome/article/details/7966451 CCArray也是cocos2d-x自己写的类.它相当于是objc的NSArray.在coc ...