一本通 1292:宠物小精灵之收服
作者:互联网
宠物小精灵之收服
二维费用背包
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
//Mystery_Sky
//
#define M 5000
int f[M][M];
int n, m, k;
int a[M], b[M], c[M];
int main() {
scanf("%d%d%d", &n, &m, &k);
for(int i = 1; i <= k; i++) scanf("%d%d", &a[i], &b[i]);
for(int i = 1; i <= k; i++) {
for(int j = n; j >= a[i]; j--) {
for(int l = m; l >= b[i]; l--) {
f[j][l] = max(f[j][l], f[j-a[i]][l-b[i]]+1);
}
}
}
int ans;
for(ans = 0; ans <= m; ans++) if(f[n][ans] == f[n][m]) break;
printf("%d %d\n", f[n][m], m - ans);
return 0;
}
标签:int,d%,收服,小精灵,ans,1292,include 来源: https://www.cnblogs.com/Benjamin-cpp/p/10994541.html