-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayThePrice_UVA10313.cpp
116 lines (101 loc) · 2.38 KB
/
payThePrice_UVA10313.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("payThePrice_UVA10313.in");
ofstream fout("payThePrice_UVA10313.out");
int main()
{
vector<vector<long long>> dp(301, vector<long long>(301, 0));
dp[0][0] = 1;
for (int c = 1; c <= 300; ++c)
{
for (int p = c; p <= 300; ++p)
{
for (int k = 1; k <= p; ++k)
{
dp[p][k] += dp[p - c][k - 1];
}
}
}
while (true)
{
string in = "", temp = "";
vector<int> a;
getline(fin, in);
if (in == "")
{
break;
}
int size0 = in.size();
for (int i = 0; i <= size0 - 1; ++i)
{
if (in[i] == ' ')
{
a.push_back(stoi(temp));
temp = "";
}
else
{
temp += in[i];
}
}
a.push_back(stoi(temp));
int size1 = a.size();
if (size1 == 1)
{
if (a[0] == 0)
{
fout << "1\n";
continue;
}
long long ans = 0;
for (int i = 1; i <= a[0]; ++i)
{
ans += dp[a[0]][i];
}
fout << ans << '\n';
}
else if (size1 == 2)
{
if (a[0] == 0)
{
fout << "1\n";
continue;
}
long long ans = 0;
for (int i = 1; i <= a[1] && i <= 300; ++i)
{
ans += dp[a[0]][i];
}
fout << ans << '\n';
}
else
{
if (a[0] == 0 && a[1] == 0)
{
fout << "1\n";
continue;
}
else if (a[1] > a[0])
{
fout << "0\n";
continue;
}
long long ans = 0;
for (int i = a[1]; i <= a[2] && i <= 300; ++i)
{
ans += dp[a[0]][i];
}
fout << ans << '\n';
}
}
return 0;
}