Cloud clipboard
AC Code
使用状态压缩 DP 和 SOS 解决 CF165E 的 AC 代码。
#include<bits/stdc++.h>
#ifndef ONLINE_JUDGE
// #define OPEN_FILE
// #define OPEN_TIME
#endif
#define AC return 0;
#define lowbit(x) (x&(-x))
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
using namespace std;
const int maxn=1e6+10,INF=0x3f3f3f3f,mod=1e9+7;
const double eps=1e-8,Pi=acos(-1);
mt19937_64 mt(1145);
int n,m=22,full=(1<<22)-1;
int a[maxn],b[1<<22];
void solve() {
for(int i=1;i<=m;++i) {
for(int S=0;S<(1<<m);++S) {
if(S&(1<<(i-1)))
b[S]=max(b[S],b[S^(1<<(i-1))]);
}
}
for(int i=1;i<=n;++i)
cout<<b[full^a[i]]<<" ";
cout<<"\n";
}
void init() {
cin>>n;
memset(b,-1,sizeof(b));
for(int i=1;i<=n;++i)
cin>>a[i],b[a[i]]=a[i];
}
int main() {
#ifdef OPEN_FILE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
#ifdef OPEN_TIME
auto StartTime=clock();
#endif
// ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
int T=1;
// cin>>T;
// while(cin>>n) {
while(T--) {
init();
solve();
}
#ifdef OPEN_TIME
cerr<<"used: "<<(double)(clock()-StartTime)/CLOCKS_PER_SEC*1000<<" ms"<<endl;
#endif
AC
}