-
Notifications
You must be signed in to change notification settings - Fork 0
/
1288.c
60 lines (49 loc) · 1.35 KB
/
1288.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
#include <stdio.h>
#include <stdlib.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
int main()
{
int testes; scanf("%d", &testes);
while(testes--)
{
int n; scanf("%d", &n);
int matriz_misseis[2][n+1];
matriz_misseis[0][0] = 0; matriz_misseis[1][0] = 0;
for(int i=1; i<n+1; i++)
{
for(int j=0; j<2; j++)
{
scanf("%d", &matriz_misseis[j][i]);
}
}
int k, r; scanf("%d %d", &k, &r);
int matriz_resposta[n+1][k+1];
for(int i=0; i<n+1; i++)
{
matriz_resposta[i][0] = 0;
for(int j=0; j<k+1; j++)
{
matriz_resposta[0][j] = 0;
}
}
for(int i=1; i<n+1; i++)
{
for(int j=1; j<k+1; j++)
{
if(matriz_misseis[1][i] > j)
{
matriz_resposta[i][j] = matriz_resposta[i-1][j];
} else {
matriz_resposta[i][j] = max(matriz_resposta[i-1][j], (matriz_resposta[i-1][j-(matriz_misseis[1][i])] + matriz_misseis[0][i]));
}
}
}
if(matriz_resposta[n][k] >= r)
{
printf("Missao completada com sucesso\n");
} else {
printf("Falha na missao\n");
}
}
return 0;
}