본문 바로가기
둥지/알고리즘

[코드업 3704] 계단 오르기2

by 까닭 2023. 3. 8.

문제링크

#include <iostream>

long long int res[1001];

long long int f(int n)
{
    if (1 == n) 
    	return res[1] = 1; 
    
    if (2 == n) 
	    return res[2] = 2;
        
    if (3 == n) 
	    return res[3] = 4;
        
    if (n <= 1000 && 0 != res[n]) 
    	return res[n];

    return res[n] = f(n - 1) + f(n - 2) + f(n - 3);
}

int main()
{
    int n;
    std::cin >> n;
    std::cout << f(n);

    return 0;
}

 

'둥지 > 알고리즘' 카테고리의 다른 글

[프로그래머스] 프로세스  (0) 2023.05.04
[프로그래머스] 연속 부분 수열 합의 개수  (0) 2023.05.02
[백준 9934] 완전 이진 트리  (0) 2023.03.01
map 구현  (0) 2023.02.27
[프로그래머스] 컨트롤 제트  (0) 2023.02.26