题目链接:点击查看

题目大意:给出 nnn 个数,问能否在数列中找到一个数,满足 ai&aj=0a_i\& a_j=0ai​&aj​=0

题目分析:题目中的式子可以转换为,aia_iai​ 是 aja_jaj​ 补集的子集,然后就是 SOSdpSOSdpSOSdp 的模板题了,因为输出的答案涉及到了 −1-1−1,所以可以将 dpdpdp 初始化为 −1-1−1,然后直接维护每个超集的最大可行答案就好啦

转移的话就是子集向超集转移

代码:

// Problem: E. Compatible Numbers
// Contest: Codeforces - Codeforces Round #112 (Div. 2)
// URL: https://codeforces.com/contest/165/problem/E
// Memory Limit: 256 MB
// Time Limit: 4000 ms
//
// Powered by CP Editor (https://cpeditor.org)// #pragma GCC optimize(2)
// #pragma GCC optimize("Ofast","inline","-ffast-math")
// #pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<list>
#include<unordered_map>
#define lowbit(x) x&-x
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
template<typename T>
inline void read(T &x)
{T f=1;x=0;char ch=getchar();while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(0!=isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();x*=f;
}
template<typename T>
inline void write(T x)
{if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');
}
const int inf=0x3f3f3f3f;
const int N=1<<22;
int a[N],dp[N];
int main()
{#ifndef ONLINE_JUDGE
//  freopen("data.in.txt","r",stdin);
//  freopen("data.out.txt","w",stdout);
#endif
//  ios::sync_with_stdio(false);memset(dp,-1,sizeof(dp));int n;read(n);for(int i=1;i<=n;i++) {read(a[i]);dp[a[i]]=a[i];}for(int j=0;j<22;j++) {for(int i=0;i<1<<22;i++) {//子集向超集转移if((i>>j)&1) {dp[i]=max(dp[i],dp[i^(1<<j)]);}}}for(int i=1;i<=n;i++) {printf("%d ",dp[(N-1)^a[i]]);}return 0;
}

CodeForces - 165E Compatible Numbers(SOSdp)相关推荐

  1. CodeForces 165E Compatible Numbers

    题意:给n个数,找出与之对应取 & 等于 0的最小值 逆推 由1 << 22 -1 递推到0 题解:http://blog.csdn.net/nyist_zxp/article/d ...

  2. Codeforces Round #112 (Div. 2) E. Compatible Numbers sosdp

    传送门 文章目录 题意: 思路: 题意: 思路: 以下假设all=1<<22all=1<<22all=1<<22. 转化问题,对于每个aia_iai​我们都计算x= ...

  3. Codeforces 164 E Compatible Numbers

    主题链接~~> 做题情绪:好题,做拉的比赛的时候想了非常久,想到枚举变幻某一位的 0 为 1 .可是每一个数都这样枚举岂不超时的节奏,当时没想到事实上从大到小枚举一次就 ok 了. 解题思路: ...

  4. CodeForces - 55D Beautiful numbers

    题目链接:http://codeforces.com/problemset/problem/55/D 题意:求区间[L,R]有多少个Beautiful numbers.Beautiful number ...

  5. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  6. 【CodeForces - 746E】Numbers Exchange(贪心构造)

    题干: Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange ...

  7. *【CodeForces - 214D 】Numbers (dp,组合数学)

    题干: Furik loves writing all sorts of problems, especially such that he can't solve himself. You've g ...

  8. 【CodeForces - 1027B 】Numbers on the Chessboard (没有营养的找规律题,无聊题)

    题干: You are given a chessboard of size n×nn×n. It is filled with numbers from 11 to n2n2 in the foll ...

  9. Codeforces 215E Periodical Numbers 容斥原理

    Periodical Numbers 我们先按长度分类对于当前处理的长度k, 我们令 F[ i ] 为有长度为 i 的循环节的方案数. 然后容斥出f[ i ] 表示最小循环节是 i 的方案数, 然后加 ...

最新文章

  1. 我把SpringBoot的banner换成了美女,老板:工作不饱和,建议加班
  2. 第1章:初始C#及其开发环境
  3. python怎样导出py文件_导出python模块(到字符串或py文件)
  4. linux indent命令: 调整C原始代码文件的格式
  5. JDK1.8 新特性(全)
  6. Oracle11g:分区表数据操作出现ORA-14400异常处理
  7. mysql 开发进阶篇系列 7 锁问题(innodb锁争用情况及锁模式)
  8. CRC码计算及校验原理计算
  9. Inspinia的version 2.4模板使用的谷歌字体加载很慢问题解决
  10. 统一软件开发过程(RUP)的概念和方法
  11. 关于域名续费 域名过户转入等问题解说
  12. PMIC驱动之—PMIC硬件相关知识
  13. 系统运维工程师面试的11大热门问题
  14. 白盒测试简介与逻辑覆盖
  15. LVS负载均衡群集—NAT模式实例
  16. 直接访问html网址怎么输入,如何设置输入IP地址就直接访问到某一个网站
  17. 关于计算机网络,你需要知道的一些常识
  18. dz plugin.php,解决dz论坛提示“插件不存在或已关闭”
  19. 租房大数据-2016年如何在北京租到好房子
  20. 用Axure RP 9制作简易网易云首页

热门文章

  1. python 字典程序_Python 字典(Dictionary)操作详解
  2. c语言实验11答案,c语言实验9-11参考答案
  3. 使用DelayExchange
  4. 使用JUnit 5 执行条件和并发测试
  5. springboot-quartz工程动态调度的实现
  6. 中文和英文对应的字节
  7. 模块化操作(es6写法)
  8. 单例-初始化动作只执行一次
  9. 单继承-继承的传递性
  10. 循环嵌套小星星-嵌套循环完成案例