题目链接 \(Description\) 给定\(n\)个正整数\(a_i\).求有多少个子序列\(a_{i_1},a_{i_2},...,a_{i_k}\),满足\(a_{i_1},a_{i_2},...,a_{i_k}\) \(and\)起来为\(0\). \(n\leq10^6,\quad 0\leq a_i\leq10^6\). \(Solution\) 这个数据范围..考虑按位容斥: 令\(g_x\)表示\(x\)的二进制表示中\(1\)的个数,\(f_x\)表示有多少个\(a_i\)…
[题目链接] http://codeforces.com/problemset/problem/449/D [题目大意] 给出一些数字,问其选出一些数字作or为0的方案数有多少 [题解] 题目等价于给出一些集合,问其交集为空集的方案数, 我们先求交集为S的方案数,记为dp[S],发现处理起来还是比较麻烦, 我们放缩一下条件,求出交集包含S的方案数,记为dp[S], 我们发现dp[S],是以其为子集的方案的高维前缀和, 我们逆序求高维前缀和即可,之后考虑容斥,求出交集为0的情况, 我们发现这个容斥…
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的那…
Description 刚开始你有一个数字0,每一秒钟你会随机选择一个[0,2^n-1]的数字,与你手上的数字进行或(c++,c的|,pascal 的or)操作.选择数字i的概率是p[i].保证0<=p[i]<=1,Σp[i]=1问期望多少秒后,你手上的数字变成2^n-1. Input 第一行输入n表示n个元素,第二行输入2^n个数,第i个数表示选到i-1的概率 Output 仅输出一个数表示答案,绝对误差或相对误差不超过1e-6即可算通过.如果无解则要输出INF Sample Input 2…
[luogu 3175] [HAOI2015]按位或 题面 刚开始你有一个数字0,每一秒钟你会随机选择一个[0,2^n-1]的数字,与你手上的数字进行按位或运算.问期望多少秒后,你手上的数字变成2^n-1. 分析 前置知识:min-max容斥 记\(\max(S)\)为集合\(S\)中的最大值,\(\min(S)\)为集合\(S\)中的最小值(如果\(S=\emptyset\) ,那\(\max(S)=\min(S)=0\)),那么有 \[\max(S)=\sum _{T\subseteq S}…
考虑min-max容斥 \(E[max(S)] = \sum \limits_{T \subset S} min(T)\) \(min(T)\)是可以被表示出来 即所有与\(T\)有交集的数的概率的和的倒数 通过转化一下,可以考虑求所有与\(T\)没有交集的数的概率和 即求\(T\)的补集的子集的概率和 用FMT随意做下吧... 注意:概率为1的时候需要特判 复杂度\(O(2^n * n)\) #include <cstdio> #include <vector> #include…
Online Judge:Hdu6053 Label:容斥,前缀和 题面: 题目描述 给你一个长度为\(N\)的序列A,现在让你构造一个长度同样为\(N\)的序列B,并满足如下条件,问有多少种方案数?答案对\(1e9+7\)取模. \(1≤Bi≤Ai\) 对于任意(l,r) \((1≤l≤r≤N)\),有\(gcd(b_l,b_{l+1}...b_r)>=2\) 输入 The first line is an integer T(1≤T≤10) describe the number of te…
B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consis…
题目链接: http://codeforces.com/problemset/problem/451/E E. Devu and Flowers time limit per test4 secondsmemory limit per test256 megabytes 问题描述 Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contains fi flow…
Relatively Prime Powers CodeForces - 1036F Consider some positive integer xx. Its prime factorization will be of form x=2k1⋅3k2⋅5k3⋅-x=2k1⋅3k2⋅5k3⋅- Let's call xx elegant if the greatest common divisor of the sequence k1,k2,-k1,k2,- is equal to 11. F…