Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2915 Accepted Submission(s): 1121
c++
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 10; const int bit = (1 << 10); const int oo = 6e3 + 10; int T; int n, Query, c[maxn], dp[maxn]; int main() { #ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin); #endif scanf("%d", &T); while (T--) { scanf("%d", &n); for (register int i = 1; i <= n; ++i) { scanf("%d", &c[i]); } sort(c + 1, c + 1 + n); memset(dp, 0, sizeof(dp)); dp[0] = 1; for (register int i = 1; i <= n; ++i) { for (register int j = oo; j >= c[i]; --j) { dp[j] = dp[j - c[i]]; } } for (register int i = 1; i <= n; ++i) { for (register int j = c[i]; j <= oo; ++j) { dp[j - c[i]] |= dp[j]; } } scanf("%d", &Query); int cur; while (Query--) { scanf("%d", &cur); if (dp[cur]) { puts("YES"); } else { puts("NO"); } } } return 0; }