본문 바로가기

코딩테스트

프로그래머스_2단계_멀리 뛰기C++

 

문제풀이: 피보나치수 활용해서 풀자!

#include <string>
#include <vector>

using namespace std;

long long solution(int n) {
    long long answer = 0;
    
    vector<int>func(n+1);
    
    func[0] = 1;
    func[1] = 1;
    for (int i = 2; i <= n; i++) {
        func[i] = (func[i - 1] + func[i - 2]) % 1234567;
    }
        answer =  func[n];
    
    return answer;
}