-
Notifications
You must be signed in to change notification settings - Fork 68
/
10036.cpp
50 lines (38 loc) · 926 Bytes
/
10036.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
bool dp[10001][101];
int main(void) {
int cases;
int n, k, num;
cin >> cases;
while (cases--) {
cin >> n >> k;
rep (i, 10001) {
rep (j, 101) {
dp[i][j] = false;
}
}
dp[0][0] = true;
vector<int> nums(n);
rep (i, n) {
cin >> nums[i];
}
REP (i, 1, n+1) {
rep (j, 101) {
if (dp[i-1][j]) {
dp[i][((j + nums[i-1]) % k + k) % k] = true;
dp[i][((j -nums[i-1]) % k + k) % k] = true;
}
}
}
if (dp[n][0]) {
cout << "Divisible" << endl;
} else {
cout << "Not divisible" << endl;
}
}
return 0;
}