【高维前缀和】Codeforces165E[Compatible Numbers]题解
来源:互联网 发布:java api文档怎么看 编辑:程序博客网 时间:2024/05/20 14:41
题目概述
给出序列
解题报告
这种东西马上想到高维前缀和求超集……不过只需要求任意解,所以更简单了……
网上好像有用状压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;}
阅读全文
0 0
- 【高维前缀和】Codeforces165E[Compatible Numbers]题解
- 【高维前缀和+容斥】Codeforces449D[Jzzhu and Numbers]题解
- 【高维前缀和】SPOJ(TLE)[Time Limit Exceeded]题解
- 高维前缀和
- Codeforces 165E Compatible Numbers 题解&代码
- 【Lucas定理+高维前缀和】2017.10.26杂题[虚妄之诺]题解
- Hdu 5765 Bonds(高维前缀和)
- hihocoder1496-高维前缀和|暴力
- [高维前缀和] Codeforces 449D
- HDU 5765 Bonds(bfs+高维前缀和)
- HDU5977 Garden of Eden 树分治+高维前缀和
- HDU5977 Garden of Eden 树分治+高维前缀和
- SPOJTime Limit Exceeded 高维前缀和优化+ dp
- [Lucas + 高维前缀和] HHHOJ#75. 虚妄之诺
- [贪心 高维前缀和] BZOJ5092. 分割序列
- codeforces 165E - Compatible Numbers
- Codeforces 164 E Compatible Numbers
- CodeForces 165E Compatible Numbers
- BNN
- html从入门到放弃(4)-图片与图片的全链接和部分链接
- 御见安全态势感知:“哈里男孩”水坑攻击“脚本小子”
- TCP和UDP区别
- mybatis开发之基本流程
- 【高维前缀和】Codeforces165E[Compatible Numbers]题解
- 模仿动物行走的腿式机器人是未来发展趋势吗?
- Spring中提供的util CollectionUtils
- 关于extern关键字的解析
- 关于OpenGL的各个坐标系的理解(推荐一些别人的好文)
- Eclipse自动下载源码--Java Source Attacher插件
- 起床
- MaterialEditText的使用:输入框
- java按指定编码写入和读取文件内容的类