UVa 10465 Homer Simpson(DP 全然背包)
题意 霍默辛普森吃汉堡 有两种汉堡 一中吃一个须要m分钟 还有一种吃一个须要n分钟 他共同拥有t分钟时间
要我们输出他在尽量用掉全部时间的前提下最多能吃多少个汉堡 假设时间无法用完 输出他吃的汉堡数和剩余喝酒的时间
非常明显的全然背包问题 求两次 一次对个数 一次对时间即可了 时间用不完的情况下就输出时间的
d1为个数的 d2为时间的 dt保存时间
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 10005
using 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
UVa 10465 Homer Simpson(DP 全然背包)的更多相关文章
- UVA 10465 Homer Simpson(dp + 完全背包)
Problem C: Homer Simpson Time Limit: 3 seconds Memory Limit: 32 MB Homer Simpson, a very smart guy, ...
- 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(全然背包)
UVA 357 Let Me Count The Ways(全然背包) http://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...
- UVA 10306 e-Coins(全然背包: 二维限制条件)
UVA 10306 e-Coins(全然背包: 二维限制条件) option=com_onlinejudge&Itemid=8&page=show_problem&proble ...
- UVA.357 Let Me Count The Ways (DP 完全背包)
UVA.357 Let Me Count The Ways (DP 完全背包) 题意分析 与UVA.UVA.674 Coin Change是一模一样的题.需要注意的是,此题的数据量较大,dp数组需要使 ...
随机推荐
- 移动App服务端架构设计
我从事手机app服务端开发现在已经是3个年头,自己也整理出了一套相对好用的服务架构,写出来,跟大家一起分享.如有不足,还请多指教. 一:基础流程图. 其实有一点还需要加上,就是对json的压缩和加 ...
- 【BZOJ4590】自动刷题机
[思路分析] 比赛的时候想到了用二分+贪心,二分的部分与贪心的部分也写对了,但是由于数据范围未看没有开long long,且二分左端点赋值过小导致WA掉 正解:二分+贪心 二分代码的长度,贪心判断能否 ...
- indeed 5.13 第二次网测
题目描述,我找不见了,大概写一下想法和代码吧. 1. 没有看 2. 由于数据范围很小,就是简单的枚举,求全排列,然后更新答案. #include<bits/stdc++.h> #defin ...
- sql--Truncate Table
Truncate Table(截断表) 有时候需要清除一个表中的所有资料.要达到者个目的,一种方式是DROP TABLE 指令.不过这样整个表格就消失,而无法再被用了. 另一种方式是Delete不带w ...
- C语言笔记(二)
注释 编译器会用空格代替代码中原来的注释,并先于预处理指令执行/*…*/ 这种形式的注释不能嵌套只要斜杠(/)和星号(*)之间没有空格,都会被当作注释的开始.例如这样:y = x/*p; \ 是一个接 ...
- 分布式机器学习框架:CXXNet
caffe是很优秀的dl平台.影响了后面很多相关框架. cxxnet借鉴了很多caffe的思想.相比之下,cxxnet在实现上更加干净,例如依赖很少,通过mshadow的模板化使得gpu ...
- mysql 统计按天、星期、按月数据的各种 sql 语句 (转录)
文章主要是作为知识整理,内容略有修改,方便以后查阅,内容转摘至 陈宇衡的个人博客,欢迎前去围观. 作为演示效果,先创建一个测试表,在插入两条数据(注:时间为 datetime 类型,unix 时间戳需 ...
- Java Web_过滤器
过滤器分类: Servlet2.5: request:用户直接访问页面时,Web容器将会调用过滤器. forward:目标资源是通过RequestDispatcher的forward访问时,该过滤器将 ...
- Swift Pointer 使用指南
Overview C Syntax Swift Syntax Note const Type * UnsafePointer<Type> 指针可变,指针指向的内存值不可变. Type * ...
- C# for 遍历 IPagedList
IPagedList<Doc> ss = Doclist.ToPagedList(page, pageSize); ;i<ss.Count;i++) { var yy = ss[i] ...