8000 Merge pull request #477 from O-BQ/develop · hackerman91/basic-algo-lecture@bd18c7b · GitHub
[go: up one dir, main page]

Skip to content

Commit bd18c7b

Browse files
Merge pull request encrypted-def#477 from O-BQ/develop
Update 1256.cpp
2 parents f36a5b6 + 46e37a6 commit bd18c7b

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

0x12/solutions/1256.cpp

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : HDLay
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/189891e34a774527af857b715027b275
44
#include <bits/stdc++.h>
55
using namespace std;
66

7-
int main(void){
8-
ios::sync_with_stdio(0);
9-
cin.tie(0);
10-
11-
}
7+
int n, m, k;
8+
int comb[202][202];
9+
vector<char> ans;
10+
11+
int main(void) {
12+
ios::sync_with_stdio(0), cin.tie(0);
13+
cin >> n >> m >> k;
14+
15+
for (int i = 1; i <= 200; i++) {
16+
comb[i][0] = 1;
17+
comb[i][i] = 1;
18+
for (int j = 1; j < i; j++) {
19+
comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
20+
if (comb[i][j] > 1'000'000'000) comb[i][j] = 1'000'000'001; // 값이 1'000'000'000을 초과할 경우, 이후 연산에서의 overflow를 막기 위해 1'000'000'001로 설정
21+
}
22+
}
23+
24+
while (n && m) {
25+
if (k > comb[n + m - 1][m]) {
26+
k -= comb[n + m - 1][m];
27+
ans.push_back('z');
28+
m--;
29+
}
30+
else {
31+
ans.push_back('a');
32+
n--;
33+
}
34+
}
35+
36+
while (n--) ans.push_back('a');
37+
while (m--) ans.push_back('z');
38+
39+
if (k > 1) cout << -1;
40+
else for (auto c : ans) cout << c;
41+
}
42+
43+
/*
44+
n, m, k값을 감소시키며 가장 큰 자리수부터 문자를 확정해나간다.
45+
현재 사용할 수 있는 'a'와 'z'의 개수가 각각 n, m개일 때, (n + m)번째 자리수의 문자가 'a'일 경우의 수는 (n + m - 1)C(m) 가지이다.
46+
따라서 현재 k값이 이보다 클 경우 (n + m)번째 문자는 'z'로 확정할 수 있다.
47+
*/

0 commit comments

Comments
 (0)
0