-
Notifications
You must be signed in to change notification settings - Fork 2
/
UVA 10898 - Combo Deal.cpp
61 lines (51 loc) · 1.54 KB
/
UVA 10898 - Combo Deal.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000000
int n, in[6], co[10][7];
int ord[6], memo[10][10][10][10][10][10], combo;
int dp(int a, int b, int c, int d, int e, int f)
{
if(a > ord[0] || b > ord[1] || c > ord[2] || d > ord[3] || e > ord[4] || f > ord[5]) return inf;
if(a == ord[0] && b == ord[1] && c == ord[2] && d == ord[3] && e == ord[4] && f == ord[5]) return 0;
int &ret = memo[a][b][c][d][e][f];
if(ret != -1) return ret;
ret = inf;
int t[6] = {0};
t[0] = 1;
for(int i=0; i<n; i++){
if(i){
t[i] = 1;
t[i-1] = 0;
}
ret = min(ret, dp(a + t[0], b + t[1], c + t[2], d + t[3], e + t[4], f + t[5]) + in[i]);
}
for(int i=0; i<combo; i++){
for(int j=0; j<n; j++)
t[j] = co[i][j];
ret = min(ret, dp(a + t[0], b + t[1], c + t[2], d + t[3], e + t[4], f + t[5]) + co[i][6]);
}
return ret;
}
int main()
{
while(scanf("%d", &n) == 1){
for(int i=0; i<n; i++){
scanf("%d", &in[i]);
}
scanf("%d", &combo);
for(int i=0; i<combo; i++){
for(int j=0; j<n; j++)
scanf("%d", &co[i][j]);
scanf("%d", &co[i][6]);
}
int orders;
scanf("%d", &orders);
for(int i=0; i<orders; i++){
memset(ord, 0, sizeof ord);
for(int j=0; j<n; j++)
scanf("%d", &ord[j]);
memset(memo, -1, sizeof memo);
printf("%d\n", dp(0, 0, 0, 0, 0, 0));
}
}
}