forked from derekhh/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexicographic-steps.cpp
More file actions
64 lines (60 loc) · 847 Bytes
/
lexicographic-steps.cpp
File metadata and controls
64 lines (60 loc) · 847 Bytes
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
//lexicographic-steps.cpp
//Lexicographic paths
//Weekly Challenges - Week 9
//Author: derekhh
#include<cstdio>
using namespace std;
int n, m;
int c[21][21];
void init()
{
for (int i = 1; i <= 20; i++)
{
c[i][0] = c[i][i] = 1;
for (int j = 1; j < i; j++)
c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
}
}
int main()
{
init();
int t;
scanf("%d", &t);
while (t--)
{
int k;
scanf("%d%d%d", &n, &m, &k);
int cx = 0, cy = 0;
while (cx != n || cy != m)
{
int nH = n - cx, nV = m - cy;
if (nH == 0)
{
printf("V");
cy++;
}
else if (nV == 0)
{
printf("H");
cx++;
}
else
{
int temp = c[nH + nV - 1][nH - 1];
if (k >= temp && temp > 0)
{
printf("V");
k -= temp;
cy++;
}
else
{
printf("H");
cx++;
}
}
}
printf("\n");
}
return 0;
}