Codeforces - Jzzhu and Numbers
題目連結:Codeforces - Jzzhu and Numbers
考慮反向列舉每個與運算不為0的集合個數,最後做差。
然後我們可以列舉每個最後與起來的答案,我們就可以利用容斥來做。先求出每個集合的超集個數,最後利用二進位制中1的個數來容斥。
當只有一個1的時候減去這個答案,2個1的時候,由於計算了2次所以加上,然後3個1減去依次類推。
AC程式碼:
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e6+10,mod=1e9+7;
int n,a[N],dp[N],up,pw[N],res,cnt[N];
inline void add(int &x,int y){x+=y; if(x>=mod) x-=mod;}
signed main(){
cin>>n; pw[0]=1; up=(1<<20)-1;
for(int i=1;i<=n;i++) scanf("%lld",&a[i]),pw[i]=pw[i-1]*2%mod,dp[a[i]]++;
for(int i=0;i<20;i++) for(int j=up;j>=0;j--) if(j>>i&1) add(dp[j^(1<<i)],dp[j]);
res=pw[n]-1;
for(int i=1;i<=up;i++){
cnt[i]=cnt[i>>1]+(i&1);
if(cnt[i]&1) res=(res-(pw[dp[i]]-1)+mod)%mod;
else res=(res+(pw[dp[i]]-1)+mod)%mod;
}
cout<<res;
return 0;
}
相關文章
- cf449D. Jzzhu and Numbers(容斥原理 高維字首和)
- 【數位dp】Beautiful numbers CodeForces - 55D
- Codeforces Round #189 (Div. 2) A. Magic Numbers
- Codeforces 914C Travelling Salesman and Special Numbers:數位dp
- 400多種Numbers模板 DesiGN for Numbers Templates for macMac
- different random numbers generatorrandom
- Collecting Numbers II
- Leetcode - Bitwise AND of Numbers RangeLeetCode
- LeetCode-Lexicographical NumbersLeetCode
- Find All Numbers Disappeared in an ArrayAPP
- LeetCode-Bitwise AND of Numbers RangeLeetCode
- 201-Bitwise AND of Numbers Range
- Leetcode Sum Root to Leaf NumbersLeetCode
- Leetcode Add Two NumbersLeetCode
- Quick Reference to Patch Numbers for Database PSUUIDatabase
- LeetCode 2 Add Two NumbersLeetCode
- Bitcoin Node Numbers Fall After Spam Transaction "Attack"
- Add_Two_Numbers python 求解Python
- 448. Find All Numbers Disappeared in an ArrayAPP
- Leetcode-Add Two NumbersLeetCode
- Sum Root to Leaf Numbers leetcode javaLeetCodeJava
- Add Two Numbers leetcode javaLeetCodeJava
- How to Convert Decimal Numbers to Words with PythonDecimalPython
- Quick Reference to Patchset Patch Numbers [ID 753736.1]UI
- [題解]CF55D Beautiful Numbers
- Leetcode 165 Compare Version NumbersLeetCode
- Leetcode 967 Numbers With Same Consecutive DifferencesLeetCode
- LeetCode-2 Add Two NumbersLeetCode
- LeetCode 2. Add Two NumbersLeetCode
- React數字滾動元件 numbers-scrollReact元件
- 【Lintcode】1267. Lexicographical Numbers
- Leetcode[421] Maximum XOR of Two Numbers in an ArrayLeetCode
- LeetCode- Count Numbers with Unique DigitsLeetCodeGit
- leetcode刷題--Compare Version NumbersLeetCode
- LeetCode OJ : 2 Add Two NumbersLeetCode
- 記錄:Oracle個版本的Patchset Patch NumbersOracle
- zt_dbanotes_Oracle Trace Level Event NumbersOracle
- CF1406E Deleting Numbers