Created
August 23, 2020 14:46
-
-
Save HADMARINE/ae25336d9887eac8e5810f7fd0d878aa 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 <iostream> | |
using namespace std; | |
int factorial(int num); | |
int main() { | |
int input_iter; | |
// input | |
cin >> input_iter; | |
int num_arr[input_iter]; | |
int result_arr[input_iter]; | |
for (int i = 0; i < input_iter; i++){ | |
cin >> num_arr[i]; | |
} | |
for (int iter = 0; iter < input_iter; iter++) { | |
int &curr_num = num_arr[iter], &result = result_arr[iter], numCount[3] = {0, }; | |
result = 0; | |
for (int i = curr_num / 3; i >= 0; i --) { | |
for(int j = (curr_num - i * 3) / 2; j >= 0; j--) { | |
int k = curr_num - (i * 3 + j * 2); | |
result += factorial(i + j + k) / (factorial(i) * factorial(j) * factorial(k)); | |
} | |
} | |
cout << result << endl; | |
} | |
} | |
int factorial(int num) { | |
int result = 1; | |
if (num == 0) { | |
return 1; | |
} | |
for(int i = 1; i <= num; i++ ) { | |
result *= i; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
백준 9095 : 1, 2, 3 더하기