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. phpMyAdmin下载与安装

    Part1 phpMyAdmin下载 浏览器输入网址 http://www.phpmyadmin.net 下载即可 我的下载是这样的 Part2 phpMyAdmin安装 解压下载的压缩包到apach ...

  2. Visual c++ 2012 软件错误

    vs2012 未能正确加载"Visual C++ Language Manager Package"包 解决办法 如下图所示: 到官网下载更新即可. http://www.micr ...

  3. 反射 DataTable拓展方法 转实体对象、实体集合、JSON

    Mapper类 using System; using System.Collections.Generic; using System.Data; using System.Globalizatio ...

  4. 学习Swift -- 继承

    继承 一个类可以继承另一个类的方法(methods),属性(properties)和其它特性.当一个类继承其它类时,继承类叫子类,被继承类叫超类(父类). 在 Swift 中,子类可以调用和访问父类的 ...

  5. java特点

    简单: Java语言的语法与C语言和C++语言很接近,使得大多数程序员很容易学习和使用.另一方面,Java丢弃了C++中很少使用的.很难理解的.令人迷惑的那些特性,如操作符重载.多继承.自动的强制类型 ...

  6. Delphi如何让程序最小化到任务栏(截取WM_SYSCOMMAND后,调用Shell_NotifyIcon)

    现在很多的应用程序都有这样一种功能,当用户选择最小化窗口时,窗口不是象平常那样最小化到任务栏上,而是“最小化”成一个任务栏图标.象FoxMail 3.0 NetVampire 3.0等都提供了这样的功 ...

  7. android 自定义命名空间

    一.统一的用户界面是可以使得应用程序更友好.要做到用户界面的统一,我们就必须用到风格(style)和主题(theme).自定义一个View的方法步骤如下:1.首先,在values文件夹下定义一个att ...

  8. Android 小闹钟程序

    最近写了个闹钟的程序,看到SharedPreferences在一个程序中可以共享数据,SharedPreferences是一个轻量级的键值存储机制,只可以存储基本数据类型.我就拿来用用,没想到Shar ...

  9. 2.5.1 使用alertDialog

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...

  10. 14.6.3.3 Making the Buffer Pool Scan Resistant

    14.6.3.3 Making the Buffer Pool Scan Resistant 相比使用一个严格的LRU算法,InnoDB 使用一个技术来最小化数据总量 带入到buffer pool 而 ...