Dev.baelanche

[백준 9461] 파도반 수열 본문

Data Structure & Algorithm/PS - JAVA

[백준 9461] 파도반 수열

baelanche 2019. 6. 18. 21:02
반응형

 

피보나치 수열과 비슷한 규칙을 가진 수열이다.

 

수열을 잘 살펴보면

dp[i] = dp[i-3] + dp[i-2]

와 같은 점화식을 얻을 수 있다.

 

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long dp[] = new long[101];
        dp[0] = 0;
        dp[1] = dp[2] = 1;
        
        for(int i=3; i<=100; i++)
            dp[i] = dp[i-3] + dp[i-2];
        
        int t = sc.nextInt();
        
        while(t-->0) {
            int n = sc.nextInt();
            System.out.println(dp[n]);
        }
    }
}
반응형

'Data Structure & Algorithm > PS - JAVA' 카테고리의 다른 글

[백준 1965] 상자넣기  (0) 2019.06.18
[백준 1309] 동물원  (0) 2019.06.18
[백준 16562] 친구비  (0) 2019.06.17
[백준 1976] 여행 가자  (0) 2019.06.17
[백준 1717] 집합의 표현  (0) 2019.06.17
Comments