-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchefuni.cpp
More file actions
62 lines (59 loc) · 2.35 KB
/
chefuni.cpp
File metadata and controls
62 lines (59 loc) · 2.35 KB
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
#include <iostream>
#include <algorithm>
using namespace std;
int three_min(int a, int b, int c) {
return min(a, min(b, c));
}
int seven_min(int a, int b, int c, int d, int e, int f, int g) {
return min(a, min(b, min(c, min(d, min(e, min(f, g))))));
}
int main(int argc, char const *argv[]) {
int T;
cin>>T;
for (int i = 0; i < T; i++) {
int X, Y, Z, A, B, C;
cin>>X>>Y>>Z>>A>>B>>C;
int path[X+1][Y+1][Z+1];
for (int z = 0; z <= Z; z++) {
for (int y = 0; y <= Y; y++) {
for (int x = 0; x <= X; x++) {
if (z == 0) {
if (x == 0) {
if (y == 0)
path[x][y][z] = 0;
else
path[x][y][z] = A+path[x][y-1][z];
}
else {
if (y == 0)
path[x][y][z] = A+path[x-1][y][z];
else
path[x][y][z] = three_min(A+path[x-1][y][z], A+path[x][y-1][z],
B+path[x-1][y-1][z]);
}
}
else {
if (x == 0) {
if (y == 0)
path[x][y][z] = A+path[x][y][z-1];
else
path[x][y][z] = three_min(A+path[x][y-1][z], A+path[x][y][z-1],
B+path[x][y-1][z-1]);
}
else {
if (y == 0)
path[x][y][z] = three_min(A+path[x-1][y][z], A+path[x][y][z-1],
B+path[x-1][y][z-1]);
else
path[x][y][z] = seven_min(A+path[x-1][y][z], A+path[x][y-1][z], A+path[x][y][z-1],
B+path[x-1][y-1][z], B+path[x-1][y][z-1], B+path[x][y-1][z-1],
C+path[x-1][y-1][z-1]);
}
}
}
}
}
cout<<path[X][Y][Z]<<endl;
}
return 0;
}