UVA 10465 0-1背包(无限) (DAG动态规划)
来源:互联网 发布:二维码扫描软件ios 编辑:程序博客网 时间:2024/06/05 01:09
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 543 5 55
17 18 99
Sample Output
1817
5 9
#include "stdio.h"#include "string.h"#include "algorithm"using namespace std;int main(){int m,n,t;int dp[10010];while(scanf("%d%d%d",&m,&n,&t)!=EOF){for(int i=0;i<10010;i++){dp[i]=-19999; } dp[0]=0;for(int i=1;i<=t;i++){if(i>=m){dp[i]=max(dp[i],dp[i-m]+1);}if(i>=n){dp[i]=max(dp[i],dp[i-n]+1);}}int i;for( i=t;i>0;i--){if(dp[i]>0)break;}//printf("%d\n",dp[t]);if(i==t)printf("%d\n",dp[i]);else{printf("%d %d\n",dp[i],t-i);}}}
0 0
- UVA 10465 0-1背包(无限) (DAG动态规划)
- UVA 103 Stacking Boxes (DAG上的动态规划)
- UVa 437 - The Tower of Babylon(DAG动态规划)
- DAG 上的动态规划(白书)
- DAG 上的动态规划(一)
- 0-1背包算法(动态规划)
- 0-1背包问题(动态规划)
- 0-1背包问题(动态规划)
- 动态规划(0-1背包问题)
- 0-1背包问题(动态规划)
- 0-1背包问题(动态规划)
- 0-1背包问题(动态规划)
- 0/1背包问题(动态规划)
- 0-1背包问题(动态规划)
- 0-1背包(动态规划)
- 0-1背包 (动态规划)
- 动态规划(0-1背包问题)
- 0/1背包问题(动态规划)
- hibernate中的多对多
- hive的基本操作(重点)
- 程序员应该具备的十个项目习惯
- dijkstra求多条最短路径(附源码)
- php复习 第三天 自定义函数
- UVA 10465 0-1背包(无限) (DAG动态规划)
- flume配置及案例
- JavaScript基础学习笔记(菜鸟必看篇)
- 布隆过滤器(Bloom Filter)的原理
- 剑指Offer(面试题40~42)
- 今年在影院看的电影。。
- 关于单选框传值到input内小结(循环可用)
- 洛谷1024 一元三次方程求解
- java面试题:String字面值对象和构造方法创建对象的区别