Uva--10465(动规,完全背包)

2014-08-02 16:07:13

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

思路:简单的完全背包,不赘述了。
 1 /*************************************************************************
 2     > File Name: c.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Wed 30 Jul 2014 01:37:57 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <iostream>
13 #include <algorithm>
14 using namespace std;
15 
16 int main(){
17     int v[2],n,m,t;
18     int dp[20005];
19     int num[20005];
20     while(scanf("%d%d%d",&m,&n,&t) == 3){
21         v[0] = m;
22         v[1] = n;
23         memset(dp,0,sizeof(dp));
24         memset(num,0,sizeof(num));
25         for(int i = 0; i < 2; ++i){
26             for(int j = v[i]; j <= t; ++j){
27                 if(dp[j - v[i]] + v[i] > dp[j]){
28                     dp[j] = dp[j - v[i]] + v[i];
29                     num[j] = num[j - v[i]] + 1;
30                 }
31                 else if(dp[j - v[i]] + v[i] == dp[j] && num[j - v[i]] >= num[j])
32                     num[j] = num[j - v[i]] + 1;
33             }
34         }
35         printf("%d",num[t]);
36         if(dp[t] < t)
37             printf(" %d",t - dp[t]);
38         printf("\n");
39     }
40     return 0;
41 }

 

 
posted @ 2014-08-02 16:08  Naturain  阅读(120)  评论(0编辑  收藏  举报