-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12852.cpp
More file actions
51 lines (47 loc) · 950 Bytes
/
Copy path12852.cpp
File metadata and controls
51 lines (47 loc) · 950 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
#include <stdio.h>
#include <vector>
#define INF 987654321
using namespace std;
vector<int> answer;
vector<int> dp, tmp;
void dfs(int now, int cnt, vector<int> &acc)
{
acc.push_back(now);
dp[now] = cnt;
if (now == 1)
{
if (answer.size() == 0 || answer.size() > acc.size())
{
answer = acc;
}
}
else
{
if (now % 3 == 0 && dp[now / 3] > cnt + 1)
{
dfs(now / 3, cnt + 1, acc);
}
if (now % 2 == 0 && dp[now / 2] > cnt + 1)
{
dfs(now / 2, cnt + 1, acc);
}
if (dp[now - 1] > cnt + 1)
{
dfs(now - 1, cnt + 1, acc);
}
}
acc.pop_back();
}
int main()
{
int N;
scanf("%d", &N);
dp.assign(N + 1, INF);
dfs(N, 0, tmp);
printf("%lu\n", answer.size() - 1);
for (int i = 0; i < answer.size(); i++)
{
printf("%d ", answer[i]);
}
return 0;
}