Baekjoon

[#2748] 피보나치 수 2

강람이 2020. 3. 10. 21:45
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
#include <iostream>
#include <vector>
 
using namespace std;
 
vector<long long> cache(91-1);
 
long long fibo(int n) {
    if (n <= 1)
        return n;
    
    long long& ret = cache[n];
 
    if (ret != -1) {
        return ret;
    }
 
    return ret = fibo(n - 2+ fibo(n - 1);
}
 
int main() {
    int n;
    cin >> n;
 
    cout <<fibo(n);
 
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

자꾸 오답이 나오길래 뭔가 했더니 int 형 범위를 넘어서였다. 그래서 long long 으로 바꿔줌