题解 CF1975F Set
upd,题解已经过审过,修改了定理 1 处的笔误
好题!于是写一篇题解记录一下。
乍一看无论怎么做时间复杂度都是
遇事不决,先推式子
这里我们钦定读者已经掌握了艾弗森括号。
我们约定大写字母表示集合,小写字母表示其对应的二进制表示。约定映射
先指出两个显然的定理:
- 若有
a\in f^{-1}(s) ,则a+1\in f^{-1}(s\times2) 。
此处的s\times2 即s 右移一位。 - 若有
S\in f^{-1}(a),S\in f^{-1}(b) ,则S\in f^{-1}(a\wedge b) 。
对于某个已经在开头
对于下面一种情况,显然有:
分讨
若
再把之前的第一式也放过来:
利用定理二合并:
另一种情况的讨论同理,读者自推不难,这里只放出结果。
- 当
n-1\in S 时:\forall t\in[0,2^{n-1}),|S\cap f^{-1}(t)|\in^?f^{-1}(v_{t}\wedge(v_{t+2^{n-1}}\times2))) - 当
n-1\notin S 时:\forall t\in[0,2^{n-1}),|S\cap f^{-1}(t)|\in^?f^{-1}(v_{t}\wedge v_{t+2^{n-1}})
推到这里,我们发现不妨先后钦定
AC 代码
#include <iostream>
#include <cstdio>
#include <cctype>
#include <vector>
using namespace std;
inline void read(int &x)
{
char c=getchar();x=0;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-48,c=getchar();
}
vector<int> V,ans;
void dfs(int s,vector<int> v,int l)
{
if(l==0)
{
if(v[0]&1) ans.push_back(s);
return;
}
int n=1<<l;
vector<int> sub;
for(int i=0;i<n>>1;i++) sub.push_back(v[i]&v[i+(n>>1)]);
dfs(s,sub,l-1);sub.clear();
for(int i=0;i<n>>1;i++) sub.push_back(v[i]&(v[i+(n>>1)]>>1));
dfs(s|(1<<l>>1),sub,l-1);
}
int main()
{
int n=0,l=0;
read(l);n=1<<l;
for(int i=1,u;i<n;i++) read(u),V.push_back(u);
V.insert(V.begin(),1);
dfs(0,V,l);
printf("%d\n",ans.size());
for(int i:ans) printf("%d\n",i);
return 0;
}