-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomerSimpsonOJ.cpp
94 lines (81 loc) · 1.74 KB
/
HomerSimpsonOJ.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
while (true)
{
int m = -1, n = -1, t = -1;
cin >> m >> n >> t;
if (m == -1)
{
break;
}
vector<int> dp(t + 1, 0);
for (int i = 0; i <= t; ++i)
{
if (i < m && i < n)
{
dp[i] = 0;
}
else
{
if (i >= m && i >= n)
{
dp[i] = max(dp[i - m], dp[i - n]);
}
else if (i >= m)
{
dp[i] = dp[i - m];
}
else
{
dp[i] = dp[i - n];
}
if (dp[i] != 0)
{
++dp[i];
}
else if (i == m || i == n)
{
dp[i] = 1;
}
}
}
int j = t;
while (dp[j] == 0 && j >= 0)
{
--j;
}
if (j == -1)
{
cout << '0';
if (t > 0)
{
cout << ' ' << t;
}
cout << '\n';
}
else
{
cout << dp[j];
if (j != t)
{
cout << ' ' << t - j;
}
cout << '\n';
}
}
cout.flush();
return 0;
}