解析:
如果累加起来之和<230 那么一定是不能装满的
如果累加起来之和>=230 那么一定可以装满的。我们从大到小排序物品的容量,然后计算。因为每件物品都是2的幂次,所以一定可以恰好装满2^30
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
#define x first
#define y second
const int N=1e5+10000;
int t,n;
PII a[N];
int ans[N];
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i].x);
a[i].y=i;
}
ll res=(1LL)<<30;
sort(a+1,a+1+n);
memset(ans,0,sizeof ans);
for(int i=n;i>=1;i--)
{
if(res>=(1LL)<<a[i].x)
{
res-=(1LL)<<a[i].x;
ans[a[i].y]=1;
}
}
if(res==0)
{
for(int i=1;i<=n;i++)
{
cout<<ans[i];
}
cout<<endl;
}
else
{
cout<<"impossible"<<endl;
}
}
}