#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
typedef long long ll;
using namespace std;
ll dp[20005];
int main() {
int num[2], sum;
while (scanf("%d %d %d", &num[0], &num[1], &sum) == 3) {
memset(dp, 0, sizeof(dp));
dp[0] = 1;
for (int i = 0; i < 2; i++) {
for (int j = 0; j <= sum; j++) {
if (dp[j] && dp[j + num[i]] < dp[j] + 1) {
dp[j + num[i]] = dp[j] + 1;
}
}
}
int cnt = 0;
while (!dp[sum]) {
sum--;
cnt++;
}
printf("%lld", dp[sum] - 1);
if (cnt) printf(" %d", cnt);
printf("\n");
}
return 0;
}
uva 10465 Homer Simpson (完全背包)
原文地址:http://blog.csdn.net/llx523113241/article/details/44497449