-
Notifications
You must be signed in to change notification settings - Fork 0
/
scuba.c
71 lines (53 loc) · 1.07 KB
/
scuba.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
67
68
69
70
71
#include<stdio.h>
int max(int a,int b)
{
if(a>b) return a;
else return b;
}
int min(int a,int b)
{
if(a<b) return a;
else return b;
}
int dp[1004][22][80];
int main()
{
int c,t,a,n,ox,ni,j,k;
int oo[1002],nn[1002],w[1002];
scanf("%d",&c);
while(c)
{
scanf("%d %d",&ox,&ni);
scanf("%d",&n);
int i;
for(i=1;i<=n;i++)
{
scanf("%d %d %d",&oo[i],&nn[i],&w[i]);
}
for(j=0;j<=ox;j++)
{
for(k=0;k<=ni;k++)
dp[0][j][k]=1000000000;
}
dp[0][0][0]=0;
for(i=1;i<=n;i++)
{
for(j=0;j<=ox;j++)
{
{
for(k=0;k<=ni;k++)
{
if(j==0 &&k==0)
dp[i][j][k]=0;
else
dp[i][j][k] = min(dp[i-1][j][k], w[i] + dp[i-1][max(0,j-oo[i])][max(0,k-nn[i])]);
//printf("hi");
}
}
}
}
printf("%d\n",dp[n][ox][ni]);
c--;
}
return 0;
}