USACO Shopping Offers

Code

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
/*
ID: wcr19961
PROG: shopping
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = 7;
const int maxs = 110;
const int maxm = 1010;
int id[maxm], cnt, aim[maxn];
int dp[maxn][maxn][maxn][maxn][maxn];
int p[maxs], num[maxs], a[maxs][maxn];
int ID(int x) {
return id[x] == 0 ? id[x] = ++cnt : id[x];
}
int main() {
freopen("shopping.in", "r", stdin);
freopen("shopping.out", "w", stdout);
int s, x;
scanf("%d", &s);
for (int i = 1; i <= s; ++i) {
scanf("%d", &num[i]);
for (int j = 0; j < num[i]; ++j) {
scanf("%d", &x);
scanf("%d", &a[i][ID(x)]);
}
scanf("%d", &p[i]);
}
int b;
scanf("%d", &b);
for (int i = 1; i <= b; ++i) {
scanf("%d", &x);
a[s + i][ID(x)] = 1;
scanf("%d%d", &aim[ID(x)], &p[s + i]);
}
memset(dp, 0x3f, sizeof dp);
dp[0][0][0][0][0] = 0;
for (int i = 1; i <= s + b; ++i) {
for (int j = a[i][1]; j <= 5; ++j) {
for (int k = a[i][2]; k <= 5; ++k) {
for (int l = a[i][3]; l <= 5; ++l) {
for (int m = a[i][4]; m <= 5; ++m) {
for (int n = a[i][5]; n <= 5; ++n) {
dp[j][k][l][m][n] = min(dp[j][k][l][m][n], dp[j - a[i][1]][k - a[i][2]][l - a[i][3]][m - a[i][4]][n - a[i][5]] + p[i]);
}
}
}
}
}
}
printf("%d\n", dp[aim[1]][aim[2]][aim[3]][aim[4]][aim[5]]);
return 0;
}

支付宝扫码领红包