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数组需要使 ...
随机推荐
- CentOS7 内核参数优化
# allow testing with buffers up to 128MBnet.core.rmem_max = 134217728net.core.wmem_max = 134217728# ...
- PCB Genesis加邮票孔(线与线)实现算法
一.Genesis加邮票孔(线与线)实现算法 1.鼠标点击位置P点, 2.通过P点求出,垂足2个点:P1C与P2C (两个点即距离2条线段垂直的垂足点) 3.计算P1C到P2C方位角(假设置为变量PA ...
- B. Jeff and Periods(cf)
B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...
- [Apple开发者帐户帮助]三、创建证书(7)创建证书签名请求
Mac上的Keychain Access允许您创建证书签名请求(CSR). 启动位于的Keychain Access /Applications/Utilities. 选择Keychain Acces ...
- Appium + python - automator定位升级版操作
# coding:utf-8 """参考博客链接:https://www.cnblogs.com/yoyoketang/p/7843819.html"" ...
- 使用node成功安装完某插件typescript后,在使用时提示:tsc(或xxx)不是内部或外部命令,也不是可运行的程序或批处理文件
具体出错情形: 使用npm安装typescript明明安装成功,但在使用时一直报错,报错语句为 tsc不是内部或外部命令,也不是可运行的程序或批处理文件 具体出错原因: node未正确安装,或相关环 ...
- 一个能让cin和scanf 一样快的方法:
cin慢是有原因的,其实默认的时候,cin与stdin总是保持同步的,也就是说这两种方法可以混用,而不必担心文件指针混乱,同时cout和stdout也一样,两者混用不会输出顺序错乱.正因为这个兼容性的 ...
- 另一种压缩图片的方法---Machine learning 之 PCA(Principle Component Analysis)
PCA最主要的用途是用来减少特征向量的数目,N个特征向量 减小到 K个特征向量.如果为了可视化,k可以使3 或者 2.这样可以加速算法的学习速度. PCA用来压缩图像同一有效. 具体方式以及原理在gi ...
- JS 有趣的eval优化输入验证
//eval就是计算字符串[可以放任何js代码]里的值 . var str1='12+3'; eval(str1); . var str2='[1,2,3]'; eval(str2[]); .eval ...
- Android开发之拍照功能实现
参考链接:http://www.linuxidc.com/Linux/2013-11/92892p3.htm 原文链接:http://blog.csdn.net/tangcheng_ok/articl ...
