题目链接
考虑每个b[i]作为一个图的顶点,b[i]连边b[j]能够构造出a[k] 那么对于整个图而言,如果连成树,只能构造n-1个 a[i] ,显然该图要存在环才能构造出来。
连成环了显然这个圈里面的ai 的和为0 .那么问题就成了从A序列中选一些数出来求和为0.
const double pi = acos(-1);
const int N = 20;
const int null = 0x3f3f3f3f,INF = 1e9;
const ll mod = 998244353;
int T;
int n;
int a[N];
int main()
{
cin >> T;
while (T --)
{
cin >> n;
int res = 1;
for (int i = 1; i <= n; i ++) cin >> a[i], res *= 3;
int flag = 0;
for (int i = 1; i <= res - 1; i ++)
{
int t = i, sum = 0;
for (int i = 1; i <= n; i ++)
{
if (t % 3 == 1) sum += a[i];
if (t % 3 == 2) sum -= a[i];
t /= 3;
}
if (!sum)
{
flag = 1;
break;
}
}
if (flag) puts("YES");
else puts("NO");
}
hz020 0;
}