比赛 期末考试1 评测结果 EAAAEETTTT
题目名称 Constructive 最终得分 30
用户昵称 梦那边的美好BP 运行时间 5.789 s
代码语言 C++ 内存使用 18.80 MiB
提交时间 2026-02-08 11:51:13
显示代码纯文本
#include <cstring>
#include <iostream>
using namespace std;
const int N = 1e3 + 3;
int a[N], b[N];
int c[N];
int n;
long long x, y;
int f[N * 2][N * 2];
int main() {
    freopen("tioj_constructive.in", "r", stdin);
    freopen("tioj_constructive.out", "w", stdout);
    cin >> n >> x >> y;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    memset(f, 0x3f, sizeof(f));
    f[0][0] = 0;
    for (int i = 0; i <= x; i++) {
        for (int j = 0; j <= y; j++) {
            for (int k = 1; k <= n; k++) {
                f[i + a[k]][j + b[k]] = min(f[i + a[k]][j + b[k]], f[i][j] + c[k]);
            }
        }
    }
    if (f[x][y] >= 0x3f3f3f3f) {
        cout << "-1";
    } else {
        cout << f[x][y];
    }
    return 0;
}