-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1,2,3더하기2.cpp
63 lines (52 loc) · 887 Bytes
/
1,2,3더하기2.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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, k;
vector<string> v[12];
void input()
{
cin >> n >> k;
}
void init()
{
v[1].push_back("1");
v[2].push_back("1+1");
v[2].push_back("2");
v[3].push_back("1+1+1");
v[3].push_back("2+1");
v[3].push_back("1+2");
v[3].push_back("3");
}
string convert(int n)
{
if (n == 1) return "+1";
else if (n == 2) return "+2";
else return "+3";
}
void solution()
{
init();
for (int i = 4; i <= n; i++)
for (int j = 1; j <= 3; j++)
for (auto k : v[i - j])
v[i].push_back(k + convert(j));
if (v[n].size() < k) cout << -1;
else
{
sort(v[n].begin(), v[n].end());
cout << v[n][k - 1];
}
}
void solve()
{
input();
solution();
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}