UVA 10465 Homer Simpson(dp + 完全背包)
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
#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 + 完全背包)的更多相关文章
- UVa 10465 Homer Simpson(DP 全然背包)
题意 霍默辛普森吃汉堡 有两种汉堡 一中吃一个须要m分钟 还有一种吃一个须要n分钟 他共同拥有t分钟时间 要我们输出他在尽量用掉全部时间的前提下最多能吃多少个汉堡 假设时间无法用 ...
- UVA 10465 Homer Simpson(全然背包: 二维目标条件)
UVA 10465 Homer Simpson(全然背包: 二维目标条件) http://uva.onlinejudge.org/index.php? option=com_onlinejudge&a ...
- UVa 10465 Homer Simpson (枚举)
10465 - Homer Simpson Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...
- UVA.674 Coin Change (DP 完全背包)
UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...
- 10465 - Homer Simpson 贪心
Homer Simpson Time Limit: 3 seconds Memory Limit: 32 MB Home ...
- UVA 562 Dividing coins(dp + 01背包)
Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were figh ...
- UVA.357 Let Me Count The Ways (DP 完全背包)
UVA.357 Let Me Count The Ways (DP 完全背包) 题意分析 与UVA.UVA.674 Coin Change是一模一样的题.需要注意的是,此题的数据量较大,dp数组需要使 ...
- UVA.10130 SuperSale (DP 01背包)
UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个. ...
- USACO Money Systems Dp 01背包
一道经典的Dp..01背包 定义dp[i] 为需要构造的数字为i 的所有方法数 一开始的时候是这么想的 for(i = 1; i <= N; ++i){ for(j = 1; j <= V ...
随机推荐
- tornado学习精要
最简单的应用在程序的最顶部,我们导入了一些Tornado模块.虽然Tornado还有另外一些有用的模块,但在这个例子中我们必须至少包含这四个模块. 12341234包括了一个有用的模块(tornado ...
- MOOC即Massive Open Online Course的缩写
A man can succeed at almost anything for which he was unlimited enthusiasm. 只要有无限的热情,一个人几乎可以在任何事情上取得 ...
- Android 简单的FC
直接贴log 01-02 08:17:56.589 I/ActivityManager( 312): Start proc com.android.providers.calendar for con ...
- Python 类型
文章出处:http://www.cnblogs.com/winstic/,请保留此连接 python是动态类型语言,不需要预先声明变量的类型,变量类型和值在赋值的那一刻被初始化 python使 ...
- CENTOS elasticsearch plugin install:Failed: SSLException[java.security.ProviderException,解决
安装Elasticsearch插件时总报SSLException yum upgrade nss 解决
- 如何在eclips下将一段代码抽取为方法Extract Method
最近读了读关于重构的文章,做了个小总结(在编程思想目录下<从文章"避免复制与粘贴"到文章"Extract Method"的反思 系列>). 然后因为 ...
- Colletion View 简单的备忘
UIColletionView 这篇只是做UIColletionView的常用属性.代理方法和数据源方法的备忘,之后做一些自定义布局,增加删除动画等. UIColletionViewFlowLayou ...
- JSP面试题及答案
更新时间:2015-04-07 来源:网络 投诉删除 [看准网(Kanzhun.com)]JSP面试题频道小编搜集的范文“JSP面试题及答案”,供大家阅读参考,查看更多 ...
- bzoj 1503: [NOI2004]郁闷的出纳员 Treap
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 6263 Solved: 2190[Submit][Statu ...
- server-send event object
http://jamie-wang.iteye.com/blog/1849193 event -- onmessage, onopen, onerror 不是方法,而是事件 http://school ...