![]() | 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
题意:在保证不休息的情况下 输出吃掉的最多汉堡的数量,若一定要休息,则使休息时间尽量的短,
分析:两个dp一个时间 一个数量,且需要注意 在时间一样的情况下,保证数量最大
key:时间相同 有不同的使用方法 所以汉堡数目不是简单的加一;也许dp!!
代码:#include<stdio.h> #include<string.h> #define N 10005 #include<algorithm> using namespace std; int dp[N]; int w[5]; int sum[N]; int main() { int m,n,t; while(scanf("%d%d%d",&w[1],&w[2],&t)!=EOF) { memset(sum,0,sizeof(sum)); memset(dp,0,sizeof(dp)); for(int i=1;i<=2;i++) { for(int j=w[i];j<=t;j++) { if(dp[j]<dp[j-w[i]]+w[i]) { dp[j]=dp[j-w[i]]+w[i];//时间为背包容量,求最多汉堡数目; sum[j]=sum[j-w[i]]+1; //printf("***%d %d %d\n",j,dp[j],sum[j]); } else if(dp[j]==dp[j-w[i]]+w[i])//最大时间相等则选择最多数量 { sum[j]=max(sum[j],sum[j-w[i]]+1); // printf("####%d %d %d\n",j,dp[j],sum[j]); } } } if(dp[t]==t) printf("%d\n",sum[t]); else printf("%d %d\n",sum[t],t-dp[t]); } return 0; }