一本通 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;
}
posted @ 2019-06-09 19:47  Mystery_Sky  阅读(1057)  评论(0编辑  收藏  举报