【高维前缀和】Codeforces165E[Compatible Numbers]题解
2017-11-06 15:05
393 查看
题目概述
给出序列 {an} ,对于每个 i ,输出任意一个满足 ai and aj=0 的 aj 。解题报告
这种东西马上想到高维前缀和求超集……不过只需要求任意解,所以更简单了……网上好像有用状压DP做的……我不清楚……(高维前缀和算状压吧QAQ?)
示例程序
#include<cstdio> #include<cctype> #include<cstring> using namespace std; const int maxn=1000000,Log=22,maxs=1<<Log; int n,a[maxn+5],f[maxs]; #define Eoln(x) ((x)==10||(x)==13||(x)==EOF) inline char readc() { static char buf[100000],*l=buf,*r=buf; if (l==r) r=(l=buf)+fread(buf,1,100000,stdin); if (l==r) return EOF; else return *l++; } inline int readi(int &x) { int tot=0,f=1;char ch=readc(),lst='+'; while (!isdigit(ch)) {if (ch==EOF) return EOF;lst=ch;ch=readc();} if (lst=='-') f=-f; while (isdigit(ch)) tot=tot*10+ch-48,ch=readc(); return x=tot*f,Eoln(ch); } int main() { freopen("program.in","r",stdin); freopen("program.out","w",stdout); readi(n);memset(f,255,sizeof(f)); for (int i=1;i<=n;i++) readi(a[i]),f[a[i]^(maxs-1)]=a[i]; for (int i=0;i<Log;i++) for (int s=0;s<maxs;s++) if (!(s&(1<<i))) if (~f[s|(1<<i)]) f[s]=f[s|(1<<i)]; for (int i=1;i<=n;i++) if (i==1) printf("%d",f[a[i]]); else printf(" %d",f[a[i]]); return putchar('\n'),0; }
相关文章推荐
- Codeforces 449D Jzzhu and Numbers(高维前缀和)
- codeforces 449D - Jzzhu and Numbers 高维前缀和 容斥
- [高维前缀和] Codeforces 449D - Jzzhu and Numbers
- CodeForces 608B Hamming Distance Sum(前缀和)
- [贪心 高维前缀和] BZOJ5092. 分割序列
- codeforces 165E - Compatible Numbers
- Codeforces 30E Tricky and Clever Password Manacher + KMP + 前缀和
- Codeforces 838A. Binary Blocks (区间筛+二维前缀和, IndiaHacks 2nd Elimination 2017 )
- 【codeforces 165E】 - Compatible Numbers 【位运算】
- Codeforces 106 D. Treasure Island(前缀和预处理)
- Hdu 5765 Bonds(高维前缀和)
- HDU5977 Garden of Eden 树分治+高维前缀和
- Codeforces 611C New Year and Domino DP+前缀和
- codeForces 660C.Hard Process(二分+前缀和)
- codeforces 708E——前缀和优化dp
- codeforces 165E - Compatible Numbers
- codeforces 776C - Molly's Chemicals 前缀和
- BZOJ 5092: 分割序列 贪心 高维前缀和
- 二维前缀和 codeforces 832C
- Codeforces 611C:New Year and Domino 二维前缀和