You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int a[55], T, n, Q;
bool b[55][55][55];
bool dp(int x, int y, int z) {
bitset<88> bs[11];
bs[0].set(0);
for (int i = 1; i <= n; i++) {
if (i == x || i == y || i == z || a[i] > 87)continue;
for (int j = 10; j >= 1; j--)
bs[j] |= bs[j - 1] << a[i];
}
return bs[10][87];
}
int main() {
scanf("%d", &T);
while (T--) {
memset(b, 0, sizeof(b));
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", a + i);
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
for (int k = j; k <= n; k++)
if (dp(i, j, k))
b[i][j][k] = true;
scanf("%d", &Q);
while (Q--) {
int xx[3];
scanf("%d%d%d", &xx[0], &xx[1], &xx[2]);
sort(xx, xx + 3);
puts(b[xx[0]][xx[1]][xx[2]] ? "Yes" : "No");
}
}
return 0;
}