본문 바로가기

프로그래머스 문제풀이/LEVEL 2

[C++] 프로그래머스 문제풀이 LEVEL 2 멀리 뛰기

 

 

https://school.programmers.co.kr/learn/courses/30/lessons/12914?language=cpp 

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#include <string>
#include <vector>

using namespace std;

long long counts[2001];

long long solution(int n) {
    counts[1] = 1;
    counts[2] = 2;
    
    for (int i = 3; i <= n; ++i)
    {
        counts[i] = counts[i - 1] % 1234567 + counts[i - 2] % 1234567;
    }
    
    return counts[n] % 1234567;
}