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. crontab,at命令,常见问题

    crontab命令 前 一天学习了 at 命令是针对仅运行一次的任务,循环运行的例行性计划任务,linux系统则是由 cron (crond) 这个系统服务来控制的. Linux 系统上面原本就有非常 ...

  2. vbox端口转发

    端口转发:setting->network->adapter:attached to NAT.port forwarding rules->name    protocol     ...

  3. 通过JS触发TextBox的ontextchanged事件,并获取TextBox所在GridView的那一行

    protected void txtInsNum_TextChanged(object sender, EventArgs e) { TextBox t = (TextBox)sender; Grid ...

  4. android实现对导航Tab设置下划线选中效果

    技术人员核心竞争力还是技术啊.努力提高各种实现效果.加油哦! 直接看效果.此linearLayout只有两个Button ,当选中Button1,Button1有个下划线选中效果.当选中Buton2, ...

  5. HDU_2024——判断字符串是否是c语言合法标识符

    Problem Description 输入一个字符串,判断其是否是C的合法标识符.   Input 输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是 ...

  6. VMware migration to openstack kvm

  7. iOS - UITableViewCell Custom Selection Style Color

    Customize UITextView selection color in UITableView Link : http://derekneely.com/2010/01/uitableview ...

  8. 设计模式&UML学习

    1. 1.1 1.2 2. 2.1 2.2 3.参考文档 [1] 陈金荣:http://blog.csdn.net/cjr15233661143/article/details/8532997 [2] ...

  9. Linux + Apache + MySql+ Php 配置虚拟主机

    win7:------------------------------------------------------------------------ NameVirtualHost *:80&l ...

  10. 笔记本分享无线Wifi

    两种方法: 一.使用软件分享,如Wifi共享精灵,设置非常简单. 二.开启windows 7的隐藏功能:虚拟WiFi和SoftAP(即虚拟无线AP),就可以让电脑变成无线路由器,实现共享上网,节省网费 ...