UVA 10465 —— 完全背包

11 篇文章 0 订阅

10465 - Homer Simpson

Time limit: 3.000 seconds

Return of the Aztecs

Problem C:Homer Simpson

Time Limit: 3 seconds
Memory Limit: 32 MB

Homer Simpson, a very smart guy, likes eating Krusty-burgers. It takes Homer m minutes to eat a Krusty- burger. However, there�s a new type of burger in Apu�s Kwik-e-Mart. Homer likes those too. It takes him n minutes to eat one of these burgers. Given t minutes, you have to find out the maximum number of burgers Homer can eat without wasting any time. If he must waste time, he can have beer.

Input

Input consists of several test cases. Each test case consists of three integers m, n, t (0 < m,n,t < 10000). Input is terminated by EOF.

Output

For each test case, print in a single line the maximum number of burgers Homer can eat without having beer. If homer must have beer, then also print the time he gets for drinking, separated by a single space. It is preferable that Homer drinks as little beer as possible.

Sample Input

3 5 54
3 5 55

Sample Output

18
17

Problem setter: Sadrul Habib Chowdhury
Solution author: Monirul Hasan (Tomal)

Time goes, you say? Ah no!
Alas, Time stays, we go.
-- Austin Dobson

题意是一个人要在时间t内吃汉堡,有两种汉堡,需要的时间分别为m和n,问你最多能吃多少个,如果其中有间隔输出间隔时间。

思路:只有两件物品的完全背包。

/*
ID: xinming2
PROG: stall4
LANG: C++
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
#include <stack>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <cassert>
using namespace std;
///#define Online_Judge
#define outstars cout << "***********************" << endl;
#define clr(a,b) memset(a,b,sizeof(a))
#define lson l , mid  , rt << 1
#define rson mid + 1 , r , rt << 1 | 1
#define mk make_pair
#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)
#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)
#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)
#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)
const int MAXN = 10000 + 50;
const int sigma_size = 26;
const long long LLMAX = 0x7fffffffffffffffLL;
const long long LLMIN = 0x8000000000000000LL;
const int INF = 0x7fffffff;
const int IMIN = 0x80000000;
#define eps 1e-8
const int mod = (int)1e9 + 7;
typedef long long LL;
const LL MOD = 1000000007LL;
const double PI = acos(-1.0);

typedef pair<int , int> pi;
#define Bug(s) cout << "s = " << s << endl;
///#pragma comment(linker, "/STACK:102400000,102400000")
int n , m , t;
int dp[MAXN];
int main()
{

    while(~scanf("%d%d%d" , &m , &n, &t ))
    {
        clr(dp , -1);
        dp[0] = 0;
        for(int i = m ; i <= t ; i++)
        {
            if(dp[i - m] != -1)dp[i] = max(dp[i] , dp[i - m] + 1);
        }
        for(int i = n ; i <= t  ; i++)
        {
            if(dp[i - n] != -1)dp[i] = max(dp[i] , dp[i - n] + 1);
        }
        if(dp[t] != -1)printf("%d\n" , dp[t]);
        else
        {
            for(int i = t ; i >= 0 ; i--)
            {
                if(dp[i] != -1)
                {
                    printf("%d %d\n" , dp[i], t - i);
                    break;
                }
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值