您的位置:首页 > 其它

uva_10465 Homer Simpson

2012-11-05 19:06 337 查看
简单的完全背包问题
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: