Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
Description

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
解决方案:先是01背包时间,让时间尽可能不良费,在是01背包汉堡的个数,在时间尽可能不浪费的情况下尽可能吃更多的汉堡。
code:#include <iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn=10005; int dptime[maxn]; int dpcnt[maxn]; int g[3][maxn]; int main() { int a[2],t; while(~scanf("%d%d%d",&a[0],&a[1],&t)) { memset(dptime,0,sizeof(dptime)); memset(dpcnt,0,sizeof(dpcnt)); memset(g,0,sizeof(g)); for(int i=0; i<2; i++) { for(int j=a[i]; j<=t; j++) { if(dptime[j]<=dptime[j-a[i]]+a[i]) { if(dptime[j]<dptime[j-a[i]]+a[i]) { dptime[j]=dptime[j-a[i]]+a[i]; dpcnt[j]=dpcnt[j-a[i]]+1; } else { dpcnt[j]=max(dpcnt[j],dpcnt[j-a[i]]+1); } } } } if(dptime[t]==t) printf("%d\n",dpcnt[t]); else printf("%d %d\n",dpcnt[t],t-dptime[t]); } return 0; }