Ultraviolet A 10465 Homer Simpson (DP full backpack)

Source: Internet
Author: User
Zookeeper

Tom Simpson has two types of hamburgers. It takes m minutes to eat one. It takes n minutes. It takes t minutes to eat one. We need to output that he tries to use all the time. the maximum number of hamburgers you can eat. If time cannot be used up, output the number of hamburgers and the remaining time for drinking.

Obviously, the complete backpack problem is to calculate the number of pairs twice, and the time is enough when the time is not enough.

D1 is the number of D2 is the DT save time of time


#include<cstdio>#include<cstring>#include<algorithm>#define maxn 10005using namespace std;int w[2],t,d1[maxn],d2[maxn],dt[maxn];int main(){    while (scanf("%d%d%d",&w[0],&w[1],&t)!=EOF)    {        memset(d1,0x8f,sizeof(d1));        memset(dt,0,sizeof(dt));        memset(d2,0,sizeof(d2));        d1[0]=0;        for(int i=0; i<2; ++i)            for(int j=w[i]; j<=t; ++j)            {                d1[j]=max(d1[j],d1[j-w[i]]+1);                if((dt[j]<dt[j-w[i]]+w[i])||((dt[j]==dt[j-w[i]]+w[i])&&(d2[j]<d2[j-w[i]]+1)))                {                    dt[j]=dt[j-w[i]]+w[i];                    d2[j]=d2[j-w[i]]+1;                }            }        if(dt[t]==t)            printf("%d\n",d1[t]);        else            printf("%d %d\n",d2[t],t-dt[t]);    }    return 0;}

Homer Simpson
 
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



Ultraviolet A 10465 Homer Simpson (DP full backpack)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.