UVa 10465 Homer Simpson(DP 完全背包),10465homer

來源:互聯網
上載者:User

UVa 10465 Homer Simpson(DP 完全背包),10465homer


題意 霍默辛普森吃漢堡  有兩種漢堡  一中吃一個需要m分鐘  另一種吃一個需要n分鐘  他共有t分鐘時間   要我們輸出他在盡量用掉所有時間的前提下最多能吃多少個漢堡  如果時間無法用完  輸出他吃的漢堡數和剩餘喝酒的時間

很明顯的完全背包問題  求兩次  一次對個數  一次對時間就行了   時間用不完的情況下就輸出時間的

d1為個數的  d2為時間的  dt儲存時間


#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






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.