Codeforces Round #778 C. Alice and the Cake
题目链接
https://codeforces.com/problemset/problem/1654/C
- 切蛋糕,判断数组是否为合法的切割中间状态
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool ok(ll w,unordered_map<ll,int>&cnt) {
if(!w)return false;
if(cnt[w]){
cnt[w]--;
return true;
}
return ok(w/2,cnt)&&ok(w-w/2,cnt);
}
int main() {
int T;
cin>>T;
while(T--){
int n;
cin>>n;
unordered_map<ll,int>cnt;
ll sum=0;
while(n--){
ll x;
cin>>x;
cnt[x]++;
sum+=x;
}
puts(ok(sum,cnt)?"YES":"NO");
}
}
~~Jason_liu O(∩_∩)O