简单的完全背包问题
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXV 10001
int dp[MAXV];
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
#endif
int n, m, t;
while( ~scanf("%d %d %d", &n, &m, &t) ) {
memset(dp, 0, sizeof(dp)); dp[0] = 1;
for(int v = 0; v <= t-n; v ++) {
if( dp[v] ) {
dp[v+n] = max(dp[v+n], dp[v]+1);
}
}
for(int v = 0; v <= t-m; v ++) {
if( dp[v] ) {
dp[v+m] = max(dp[v+m], dp[v]+1);
}
}
if( dp[t] ) {
printf("%d\n", dp[t]-1); continue;
}
for(int v = t; v >= 0; v --) {
if( dp[v] ) {
printf("%d %d\n", dp[v]-1, t-v); break;
}
}
}
return 0;
}uva_10465 Homer Simpson
最新推荐文章于 2015-07-01 13:39:49 发布
本文介绍了如何使用C++解决完全背包问题,并提供了代码实现。文章详细解释了算法原理及其实现过程,包括动态规划的方法和边界条件的处理。
393

被折叠的 条评论
为什么被折叠?



