-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12455.cpp
More file actions
37 lines (35 loc) · 776 Bytes
/
12455.cpp
File metadata and controls
37 lines (35 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
#define mem(x, y) memset(x, y, sizeof(x));
int dp[25][1010];
bool dc[25][1010];
int a[25];
int N, sum;
bool call(int i, int rem) {
if (rem == sum) return 1;
if (i == N) return 0;
if (dc[i][rem]) return dp[i][rem];
bool x = 0, y = 0;
if (rem + a[i] <= sum) x = call(i + 1, rem + a[i]);
y = call(i + 1, rem);
dc[i][rem] = 1;
dp[i][rem] = x | y;
return dp[i][rem];
}
int main() {
int i, k, n;
int t;
scanf("%d", &t);
getchar();
while (t--) {
mem(dc, 0);
scanf("%d%d", &sum, &N);
for (i = 0; i < N; i++) scanf("%d", &a[i]);
k = call(0, 0);
if (k == 1)
puts("YES");
else
puts("NO");
}
return 0;
}