潜水员
二维费用背包
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
//Mystery_Sky
//
#define M 1000
#define INF 0x3f3f3f3f
int f[M][M];
int a[M], b[M], c[M];
int n, m, k;
int main() {
scanf("%d%d", &m, &n);
scanf("%d", &k);
for(int i = 1; i <= k; i++) scanf("%d%d%d", &a[i], &b[i], &c[i]);
memset(f, INF, sizeof(f));
f[0][0] = 0;
for(int i = 1; i <= k; i++)
for(int j = m; j >= 0; j--)
for(int l = n; l >= 0; l--) {
int x, y;
x = j + a[i], y = l + b[i];
x = x > m ? m : x;
y = y > n ? n : y;
f[x][y] = min(f[x][y], f[j][l] + c[i]);
}
printf("%d
", f[m][n]);
return 0;
}