uva 10465 (Homer Simpson) (DP)
2014-01-03 00:27
387 查看
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 integersm, 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 littlebeer as possible.
Sample Input
3 5 54 3 5 55
Sample Output
18 17
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 10010; int cost[2], t; int dp[maxn]; int main(){ while(cin >> cost[0] >> cost[1] >> t){ memset(dp , 0 , sizeof dp); dp[0] = 1; for(int i = 0;i <= t-min(cost[0] , cost[1]);i++){ if(dp[i] != 0){ for(int k = 0;k < 2;k++){ if(i+cost[k] <= t){ dp[i+cost[k]] = max(dp[i+cost[k]] , dp[i]+1); } } } } if(dp[t]){ cout << dp[t]-1 << endl; }else{ for(int i = t-1;i >= 0;i--){ if(dp[i]){ cout << dp[i]-1 << " " << t-i << endl; break; } } } } return 0; }
相关文章推荐
- UVa 10465 Homer Simpson(DP 全然背包)
- Homer Simpson - UVa 10465 dp
- UVa 10465 Homer Simpson(DP 完全背包)
- Uva 10465-Homer Simpson(DP)
- UVa 10465 Homer Simpson(DP完全背包)
- UVA 10465 Homer Simpson(全然背包: 二维目标条件)
- uva 10465 - Homer Simpson
- UVa 10465 - Homer Simpson
- UVa 10465 Homer Simpson (枚举)
- Uva-10465-Homer Simpson
- uva 10465 - Homer Simpson
- uva_10465 Homer Simpson
- UVA 10465 Homer Simpson(dp + 完全背包)
- uva10465 - Homer Simpson(完全背包)
- UVa 10465 Homer Simpson
- UVA——10465(dp)
- UVA 10465 Homer Simpson(完全背包)
- uva 10465 Homer Simpson
- UVA 10465 Homer Simpson(完全背包: 二维目标条件)
- UVa 10465 Homer Simpson (枚举)