USACO Training Section 3.3 Shopping Offers

Posted xcysblog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了USACO Training Section 3.3 Shopping Offers相关的知识,希望对你有一定的参考价值。

拿给出的每种方案作为一种物品
其他的单卖的物品也作为一种物品

拿它们去跑背包就行

注意编号对应上就行


 代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cstdio>
#include <locale>
#include <map>
using namespace std;

const int MAXN = 110;

struct ITEM {
    int tot, cst;
    int num[6];
}itm[MAXN];
int s, n, totnum;
int num[6], id[1005], req[1005], f[6][6][6][6][6];
bool usf[1005];

int main() {
    scanf("%d", &s);
    int x = 0, y = 0;
    for (int i = 1; i <= s; ++i) {
        scanf("%d", &itm[i].tot);
        for (int j = 1; j <= itm[i].tot; ++j) {
            scanf("%d%d", &x, &y);
            if (!id[x]) {
                id[x] = ++totnum;
                num[totnum] = x;
            }
            itm[i].num[id[x]] = y;
        }
        scanf("%d", &itm[i].cst);
    }
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &x);
        if (!id[x]) {
            id[x] = ++totnum;
            num[totnum] = x;
        }
        scanf("%d", &req[id[x]]);
        itm[++s].num[id[x]] = 1;
        itm[s].tot = 1;
        scanf("%d", &itm[s].cst);
    }
    memset(f, 0x3f, sizeof(f));
    f[0][0][0][0][0] = 0;
    for (int i = 1; i <= s; ++i) {
        for (int a = itm[i].num[1]; a <= req[1]; ++a) {
            for (int b = itm[i].num[2]; b <= req[2]; ++b) {
                for (int c = itm[i].num[3]; c <= req[3]; ++c) {
                    for (int d = itm[i].num[4]; d <= req[4]; ++d) {
                        for (int e = itm[i].num[5]; e <= req[5]; ++e) {
                            f[a][b][c][d][e] = min(f[a][b][c][d][e], f[a - itm[i].num[1]][b - itm[i].num[2]][c - itm[i].num[3]][d - itm[i].num[4]][e - itm[i].num[5]] + itm[i].cst);
                        }
                    }
                }
            }
        }
    }
    printf("%d
", f[req[1]][req[2]][req[3]][req[4]][req[5]]);
    return 0;
}

  

以上是关于USACO Training Section 3.3 Shopping Offers的主要内容,如果未能解决你的问题,请参考以下文章

等差数列 [USACO Training Section 1.4]

回文检测 [USACO Training Section 1.3]

USACO Training Section3.1 Score Inflation

USACO Training Section 1.1 题解(共4题)

usaco-Section 3.1-Contact

usaco-Section 3.1-Stamps