大致题意:
给你 n 件物品和它们的重量的所有组合 (空组合也算),问你是否存在这样的 n 件物品。
解题报告:
不存在的情况:最小重量 >0 || 构成集合的最少重量书 >n
首先对这些重量排序,次小的一定是答案集合里的,在之后每找到一个数(答案集合里存在的),用它来更新之前找到的合法重量的所有组合,然后再后面的扫面过程中,直接判断是否存在更新的组合情况中。
#define first f
#define second s
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int MOD=1e9+7;
const int maxn=3e5+5;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const double PI=acos(-1.0);
const double e=2.718281828459;
int p[maxn];
unordered_multiset<int>s1,s2;
vector<int>v;
unordered_map<int,int>MP;
int main()
{
int n,m=0;
scanf("%d",&n);
int cnt=(1<<n);
for(int i=1;i<=cnt;i++) scanf("%d",&p[i]);
sort(p+1,p+cnt+1);
if(p[1]>0){
printf("impossible");return 0;
}
for(int i=2;i<=cnt;i++){
if(MP[p[i]]){
MP[p[i]]--;
}
else{
m++;
v.pb(p[i]);
for(auto it:s1){
s2.insert(it+p[i]);
}
for(auto it:s2){
s1.insert(it);
MP[it]++;
}
s1.insert(p[i]);
s2.clear();
}
if(m>n){
printf("impossible");return 0;
}
}
for(auto it:v){printf("%d\n",it);}
return 0;
}