UVA10465 Homer Simpson递推
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10465 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
问题链接:UVA10465 Homer Simpson
问题简述:(略)
问题分析:递推问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10465 Homer Simpson */
#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
int dp[N];
int main()
{
int m, n, t;
while (~scanf("%d%d%d", &m, &n, &t)) {
int cur = 0;
memset(dp, 0, sizeof dp);
dp[0] = 1;
for (int i = 0; i <= t; i++)
if (dp[i]) {
dp[n + i] = dp[i] + 1;
dp[m + i] = dp[i] + 1;
cur = i;
}
printf(dp[t] == 0 ? "%d %d\\n" : "%d\\n", dp[cur] - 1, t - cur);
}
return 0;
}
以上是关于UVA10465 Homer Simpson递推的主要内容,如果未能解决你的问题,请参考以下文章