【高维前缀和】Codeforces165E[Compatible Numbers]题解

题目概述

给出序列 {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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值