백준
[1003] 피보나치 함수
Jcoder
2018. 7. 23. 20:15
#include <iostream>#define MAX 40using namespace std;int memo_fib(int n);int main(){int n, testcase;cin >> testcase;for (int i = 0; i < testcase; i++){cin >> n;if (n == 0)cout << "1 0\n";elsecout << memo_fib(n-2) << " " << memo_fib(n - 1) << endl;}return 0;}int memo_fib(int n){static int M[MAX] = { 1, 1 };if (n <= 1)return M[n];if (M[n] == 0)M[n] = memo_fib(n - 1) + memo_fib(n - 2);return M[n];}