-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamtyres.c
56 lines (48 loc) · 920 Bytes
/
samtyres.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
#include <stdio.h>
#define INFINITY 9999999
int N;
int min = INFINITY;
int visited[100];
struct tyre_pressure {
int inflate;
int deflate;
} tyre[100];
void solve(int n, int value)
{
int i;
if (n == N-1) {
if (value < min)
min = value;
printf("min value = %d\n", value);
return;
}
printf("n: %d, value: %d\n", n, value);
for (i=0; i<N; i++) {
if (value + tyre[i].inflate <= 100 && ((value + tyre[i].inflate) - tyre[i].deflate) >= 0 && !visited[i]) {
value = (value + tyre[i].inflate) - tyre[i].deflate;
visited[i] = 1;
solve(n+1, value);
visited[i] = 0;
}
}
}
int main()
{
int i;
int t,T;
scanf("%d", &T);
for (t=1; t<= T; t++) {
scanf("%d", &N);
for (i=0; i<N; i++) {
scanf("%d", &tyre[i].inflate);
}
for (i=0; i<N; i++) {
scanf("%d", &tyre[i].deflate);
visited[i] = 0;
}
min = INFINITY;
solve(0,0);
printf("Case #%d: %d\n", t, min);
}
return 0;
}