UVA 10465 0-1背包(无限) (DAG动态规划)

来源:互联网 发布:二维码扫描软件ios 编辑:程序博客网 时间:2024/06/05 01:09


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 543 5 55
17 18 99

Sample Output

1817
5 9
#include "stdio.h"#include "string.h"#include "algorithm"using namespace std;int main(){int m,n,t;int dp[10010];while(scanf("%d%d%d",&m,&n,&t)!=EOF){for(int i=0;i<10010;i++){dp[i]=-19999; } dp[0]=0;for(int i=1;i<=t;i++){if(i>=m){dp[i]=max(dp[i],dp[i-m]+1);}if(i>=n){dp[i]=max(dp[i],dp[i-n]+1);}}int i;for( i=t;i>0;i--){if(dp[i]>0)break;}//printf("%d\n",dp[t]);if(i==t)printf("%d\n",dp[i]);else{printf("%d %d\n",dp[i],t-i);}}}


0 0
原创粉丝点击