-
Notifications
You must be signed in to change notification settings - Fork 0
/
12101번 1, 2, 3 더하기 2
74 lines (68 loc) · 1.03 KB
/
12101번 1, 2, 3 더하기 2
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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long int arr[1000001];
void print_nk(int n, int k) {
if (n >= 4) {
if (arr[n - 1] + arr[n - 2] < k) {
cout << "3+";
print_nk(n - 3, k - arr[n - 1] - arr[n - 2]);
}
else if (arr[n - 1] < k) {
cout << "2+";
print_nk(n - 2, k - arr[n - 1]);
}
else {
cout << "1+";
print_nk(n - 1, k);
}
}
else {
if (n == 1) {
cout << "1";
}
else if (n == 2) {
if (k == 1) {
cout << "1+1";
}
else {
cout << "2";
}
}
else {
if (k == 1) {
cout << "1+1+1";
}
else if (k == 2) {
cout << "1+2";
}
else if (k == 3) {
cout << "2+1";
}
else {
cout << "3";
}
}
}
}
int main() {
for (int i = 0; i < 1000001; i++) {
arr[i] = 0;
}
arr[1] = 1;
arr[2] = 2;
arr[3] = 4;
for (int i = 4; i < 1000001; i++) {
arr[i] = (arr[i - 1] + arr[i - 2] + arr[i - 3]) % 1000000009;
}
int n, k;
cin >> n >> k;
if (arr[n] < k) {
cout << "-1";
}
else {
print_nk(n, k);
}
return 0;
}