public int solution(int n) {
return dfs(n, 0);
}
private int dfs(int value, int cnt) {
if (value < 1 || 2 * Math.log(value) / Math.log(3) < cnt) {
return 0;
}
if (value == 3) {
return (cnt == 2) ? 1 : 0;
}
int result = 0;
if (value % 3 == 0 && cnt >= 2) {
result += dfs(value / 3, cnt - 2);
}
result += dfs(value - 1, cnt + 1);
return result;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/1831