-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABC_202_D.cpp
64 lines (53 loc) · 945 Bytes
/
ABC_202_D.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
#include <iostream>
#include <string>
using namespace std;
long long C[61][61];
// Returns value of Binomial Coefficient C(n, k)
long long binomialCoeff(int n, int k)
{
int i, j;
// Caculate value of Binomial Coefficient
// in bottom up manner
for (i = 0; i <= n; i++) {
for (j = 0; j <= min(i, k); j++) {
// Base Cases
if (j == 0 || j == i)
C[i][j] = 1;
// Calculate value using previously
// stored values
else
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
}
return C[n][k];
}
string go(int a, int b, long long k) {
if (k <= 0 || a <= 0 || b <= 0)
{
string ret = "";
while (a--)
{
ret += 'a';
}
while (b--)
{
ret += 'b';
}
return ret;
}
// a
long long c = binomialCoeff(a + b - 1, a - 1);
if (k <= c)
{
return 'a' + go(a - 1, b, k);
}
else
{
return 'b' + go(a, b - 1, k - c);
}
}
int main() {
long long a, b, k;
cin >> a >> b >> k;
cout << go(a, b, k) << endl;
}