forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10036.cpp
73 lines (68 loc) · 881 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <bits/stdc++.h>
using namespace std;
#define MAXN 102
int Table[10002][MAXN], K, N, V, F;
void Cal()
{
int i, j;
int pos, neg;
for (i = 2; i <= N; i++)
{
scanf("%d", &V);
if (V)
{
F = 1;
}
//V = fabs(V);
for (j = 0; j < K; j++)
{
if (Table[i - 1][j])
{
pos = (j + V) % K;
neg = (j - V) % K;
pos = fabs(pos);
neg = fabs(neg);
Table[i][pos] = 1;
Table[i][neg] = 1;
}
}
}
if (Table[N][0] == 1)
{
printf("Divisible\n");
}
else
{
printf("Not divisible\n");
}
}
void INI()
{
int i, j;
for (i = 1; i <= N; i++)
for (j = 0; j <= K; j++)
{
Table[i][j] = 0;
}
}
int main()
{
int temp, kase;
scanf("%d", &kase);
while (kase--)
{
F = 0;
scanf("%d%d", &N, &K);
scanf("%d", &V);
V = fabs(V);
if (V)
{
F = 1;
}
temp = V % K;
INI();
Table[1][temp] = 1;
Cal();
}
return 0;
}