Codeforces Round #257 (Div. 1) D - Jzzhu and Numbers 容斥原理 + SOS dp
这个容斥没想出来。。。 我好菜啊。。
f[ S ] 表示若干个数 & 的值 & S == S得 方案数, 然后用这个去容斥。
求f[ S ] 需要用SOSdp
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int cnt[<<], bin[N], num[<<], n; int main() {
for(int i = bin[] = ; i < N; i++) bin[i] = bin[i - ] * % mod;
scanf("%d", &n);
for(int i = ; i <= n; i++) {
int x; scanf("%d", &x);
cnt[x]++;
}
for(int i = ; i < ; i++)
for(int S = ; S < ( << ); S++)
if(S >> i & ) cnt[S ^ ( << i)] += cnt[S];
LL ans = bin[n];
for(int S = ; S < ( << ); S++) {
num[S] = num[S-(S&-S)] + ;
if(num[S] & ) ans = (ans - bin[cnt[S]] + mod) % mod;
else ans = (ans + bin[cnt[S]]) % mod;
}
printf("%lld\n", ans);
return ;
} /*
*/
Codeforces Round #257 (Div. 1) D - Jzzhu and Numbers 容斥原理 + SOS dp的更多相关文章
- Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)
主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)
题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...
- Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵高速幂)
题目链接:http://codeforces.com/problemset/problem/450/B B. Jzzhu and Sequences time limit per test 1 sec ...
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)
题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...
- Codeforces Round #257 (Div. 2) B Jzzhu and Sequences
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
- Codeforces Round #257 (Div. 2) C. Jzzhu and Chocolate
C. Jzzhu and Chocolate time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children
A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA
题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路 ...
随机推荐
- MT【188】一个正切余切有关的恒等式
(2017北大特优)求$9\tan 10^\circ+2\tan 20^\circ+4\tan 40^\circ-\tan 80^\circ=$_____ A.$0$ B.$\dfrac{\sqrt ...
- Spoj 8372 Triple Sums
题意:给你n个数字,对于任意s,s满足\(s=u_i+u_j+u_k,i<j<k\),要求出所有的s和对应满足条件的i,j,k的方案数 Solution: 构造一个函数:\(A(x)=\s ...
- 扩展中国剩余定理学习笔记+模板(洛谷P4777)
题目链接: 洛谷 题目大意:求同余方程组 $x\equiv b_i(mod\ a_i)$ 的最小正整数解. $1\leq n\leq 10^5,1\leq a_i\leq 10^{12},0\leq ...
- 【bzoj2961】 共点圆
http://www.lydsy.com/JudgeOnline/problem.php?id=2961 (题目链接) 题意 按照一定的顺序给出一些圆和一些点,对于每一个点问是否在所有圆内. Solu ...
- JavaScript -- 标签 , Break 和 Continue 语句
break 语句用于跳出循环. continue 用于跳过循环中的一个迭代. 标签引用,break 语句可用于跳出任何 JavaScript 代码块. demo: <!DOCTYPE html& ...
- CF1012C Hills
显然的DP是,dp[i][j][val] val是1e6的 简化 发现,其实决策很有限,最优解的i-1的val选择有限 题解 这里的一个trick是,f[i][j][0]转移不考虑a[i]和a[i-1 ...
- C++ ------ const迭代器 和 const_iterator的区别
const迭代器,顾名思义,就是不能改变的迭代器,是常量,其性质是由const决定的.比如说我们这样定义一个const迭代器. vector<,); const vector<int> ...
- 开发环境--Pipenv的使用
1.Pipenv 介绍 Pipenv是基于pip的Python包管理工具,它和pip的用法非常相似,可以看做pip的加强版. pipenv解决了旧的pip+virtualenv+requirement ...
- harbor高可用集群配置
目录 说明 双主复制 主从同步 双主复制说明 多harbor实例共享后端存储 方案说明 环境说明 配置说明 安装redis和mysql 导入registry数据库 配置harbor 挂载nfs目录 修 ...
- 生成ssh-key for GIthub
在Github里,如果我们想通过ssh的方式进行身份验证,我们就需要建立ssh-key: 方法一: git GUI,点击help,选择Generate ssh key