-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1256.cpp
More file actions
64 lines (59 loc) · 1.22 KB
/
1256.cpp
File metadata and controls
64 lines (59 loc) · 1.22 KB
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 <vector>
#include <string>
#define INF 1000000001
using namespace std;
vector<vector<int>> comb;
int main()
{
int N, M, K;
int a = 0, z = 0;
string answer = "";
cin >> N >> M >> K;
comb.assign(N + M + 1, vector<int>(N + M + 1, 1));
for (int i = 2; i <= N + M; i++)
{
for (int j = 1; j < i; j++)
{
comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
if (comb[i][j] >= INF)
{
comb[i][j] = INF;
}
}
}
if (comb[N + M][N] < K)
{
cout << -1 << endl;
}
else
{
while (K)
{
if (answer.length() == N + M)
{
break;
}
if (a == N)
{
answer += "z";
z++;
continue;
}
int standard = comb[N + M - a - z - 1][N - a - 1];
if (standard >= K)
{
answer += "a";
a++;
}
else
{
answer += "z";
K -= standard;
z++;
}
}
cout << answer << endl;
}
return 0;
}