-
Notifications
You must be signed in to change notification settings - Fork 0
/
2228.c
66 lines (48 loc) · 880 Bytes
/
2228.c
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
#include <stdio.h>
#define max 100
int irmao,irmao2,arc,tesouro[max],i,soma=0,ts=0,possivel;
int subset_sum(int *v, int n, int x)
{
int poss[5500] = {};
int i, j;
poss[0] = 1;
for(i = 0; i < n; i++)
{
for(j = x; j >= v[i]; j--)
{
if(poss[j-v[i]])
poss[j] = 1;
}
}
return poss[x];
}
int main()
{
while (scanf("%d %d %d", &irmao, &irmao2, &arc) && irmao && irmao2 && arc)
{
for(i=0;i<arc;i++)
{
scanf("%d", &tesouro[i]);
soma+=tesouro[i];
}
soma += irmao+irmao2;
printf("Teste %d\n",++ts);
if(soma%2!=0)
printf("N\n\n");
else
{
soma/=2;
if(irmao>irmao2)
soma-=irmao2;
else
soma-=irmao;
possivel = subset_sum(tesouro,arc,soma);
if(possivel)
printf("S\n\n");
else if(!possivel)
printf("N\n\n");
}
soma=0;
}
return 0;
}