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
题意:有两种汉堡一种吃一个要n分钟,一种要m分钟,现在给定t分钟。要求尽量不浪费时间去吃汉堡,求出吃汉堡的个数,如果一定要浪费时间,那么还要输出浪费掉的时间。
思路:完全背包,等于是给定两个物品,时间代表容量,价值都为1,求出dp[t]的最大值。
代码:
#include <stdio.h>
#include <string.h> int m, n, t, dp[10005], i; int max(int a, int b) {
return a > b ? a : b;
} int main() {
while (~scanf("%d%d%d", &m, &n, &t)) {
memset(dp, -1, sizeof(dp));
dp[0] = 0;
for (i = m; i <= t; i ++) {
if (dp[i - m] != - 1)
dp[i] = max(dp[i - m] + 1, dp[i]);
}
for (i = n; i <= t; i ++) {
if (dp[i - n] != -1)
dp[i] = max(dp[i - n] + 1, dp[i]);
}
if (dp[t] != -1)
printf("%d", dp[t]);
else {
for (i = t; i >= 0; i --)
if (dp[i] != -1) {
printf("%d %d", dp[i], t - i);
break;
}
}
printf("\n");
}
return 0;
}

UVA 10465 Homer Simpson(dp + 完全背包)的更多相关文章

  1. UVa 10465 Homer Simpson(DP 全然背包)

     题意 霍默辛普森吃汉堡  有两种汉堡  一中吃一个须要m分钟  还有一种吃一个须要n分钟  他共同拥有t分钟时间    要我们输出他在尽量用掉全部时间的前提下最多能吃多少个汉堡  假设时间无法用 ...

  2. UVA 10465 Homer Simpson(全然背包: 二维目标条件)

    UVA 10465 Homer Simpson(全然背包: 二维目标条件) http://uva.onlinejudge.org/index.php? option=com_onlinejudge&a ...

  3. UVa 10465 Homer Simpson (枚举)

    10465 - Homer Simpson Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...

  4. UVA.674 Coin Change (DP 完全背包)

    UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...

  5. 10465 - Homer Simpson 贪心

                                            Homer Simpson Time Limit: 3 seconds Memory Limit: 32 MB Home ...

  6. UVA 562 Dividing coins(dp + 01背包)

    Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were figh ...

  7. UVA.357 Let Me Count The Ways (DP 完全背包)

    UVA.357 Let Me Count The Ways (DP 完全背包) 题意分析 与UVA.UVA.674 Coin Change是一模一样的题.需要注意的是,此题的数据量较大,dp数组需要使 ...

  8. UVA.10130 SuperSale (DP 01背包)

    UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个. ...

  9. USACO Money Systems Dp 01背包

    一道经典的Dp..01背包 定义dp[i] 为需要构造的数字为i 的所有方法数 一开始的时候是这么想的 for(i = 1; i <= N; ++i){ for(j = 1; j <= V ...

随机推荐

  1. php多线程即时通讯

    即时通讯:推送消息http://www.workerman.net/

  2. centos下的lnmp环境搭建

    1.配置centos的第三方yum源,因为原始的yum是无法安装nginx的 wget http://www.atomicorp.com/installers/atomic  下载atomic yum ...

  3. 【转】深入 char * ,char ** ,char a[ ] ,char *a[] 内核

    原文出处:http://blog.csdn.net/daiyutage/article/details/8604720    C语言中由于指针的灵活性,导致指针能代替数组使用,或者混合使用,这些导致了 ...

  4. http知识累积

    1. http头 Host, Host请求报头域主要用于指定被请求资源的Internet主机和端口号,它通常从HTTP URL中提取出来的. 如果有黑客劫持了用户的请求,篡改了Host的内容,当请求到 ...

  5. Windows命令行下pip安装python whl包

    因为做网页爬虫,需要用到一个爬新闻的BeautifulSoup 的包,然后再关网上下的是whl包,第一次装,虽然花了点时间,最后还是装上去了,记录一下,方便下次. 先发一下官方文档地址.http:// ...

  6. matlab的二维卷积操作

    MATLAB的conv2函数实现步骤(conv2(A,B)): 其中,矩阵A和B的尺寸分别为ma*na即mb*nb ① 对矩阵A补零,第一行之前和最后一行之后都补mb-1行,第一列之前和最后一列之后都 ...

  7. C#匿名类型(Anonymous Type)学习日记

    当我们不要定义复杂的方法,事件,构造函数这样复杂的类的时候,可以动态的生成一个自定义的数据类型 --> 匿名类型. 1.定义匿名类型 定义一个匿名类型时,需要用到 var 关键字和对象初始化语法 ...

  8. windows server 2003 服务器

    服务器基本知识:可通过我的电脑属性里面查看服务器的系统. 设置固定Ip:本地连接(控制面板-网络连接)使用下面的Ip地址.通过ipconfig/all,查看DNS和ip. 远程访问服务器:我的电脑属性 ...

  9. OGNL-action

    需要注意的是,action需要先被调用到,OGNL才能成功,因为action被执行才被压入值栈 package com.wolfgang.action; import com.opensymphony ...

  10. js performance

    http://hqman.me/2012/js-module.html http://www.cnblogs.com/snandy/archive/2012/06/06/2536969.html ht ...