ALGORITHM

[JAVA] 알고리즘 : 동적 계획법- 계단 오르기

연듀 2022. 10. 24. 09:33

 

import java.util.Scanner;

public class Main{
    static int[] dy;
    public int solution(int n){
        dy[1]=1;
        dy[2]=2;
        for(int i=3; i<=n; i++){
            dy[i]=dy[i-2]+dy[i-1];
        }
        return dy[n];
    }
    public static void main(String[] args) {
        Main T = new Main();
        Scanner kb = new Scanner(System.in);
        int n = kb.nextInt();
        dy = new int[n+1];
        System.out.println(T.solution(n));
    }
}