Created
November 10, 2019 07:24
-
-
Save siisee11/8b70a8a4a7116cba513bbedce59df24b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <stdio.h> | |
int findCase(int n, int nPlus); | |
// 전역 변수를 정의할 경우 함수 내에 초기화 코드를 꼭 작성해주세요. | |
int solution(int n) { | |
int answer = 0; | |
return findCase(n - 2, 2); | |
} | |
int findCase(int n, int nPlus) { | |
int result = 0; | |
if (n < 1 || 2*log(n)/log(3) < nPlus) { | |
return 0; | |
} else if ( n == 3 && nPlus == 2){ | |
return 1; | |
} else if ( n == 3 && nPlus == 3) { | |
return 0; | |
} | |
if (n % 3 == 0 && nPlus >= 2){ | |
result += findCase(n / 3, nPlus - 2); | |
} | |
result += findCase(n - 1, nPlus + 1); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment