본문 바로가기
알고리즘 & 자료구조/백준

백준 1309

by 신재권 2021. 9. 13.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main1309_2 {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine()); //세로의 길이 : N
		int[] D = new int[N+1];
		int[] S = new int[N+1];
		final int mod = 9901;
		
		//점화식 (1차원 다이나믹으로)
		//S[i] = D[1] + D[2] + ... + D[i]
		//D[i] = D[i-1] + 2(D[i-2] + ... + D[1] + D[0])
		//D[i] = D[i-1] + 2 x S[i-2] 
		
		D[0] = 1; 
		S[0] = 1;
		D[1] = 2;
		S[1] = D[0] + D[1];
 		for(int i=2; i<=N; i++){
			D[i] = D[i-1] + 2 * S[i-2];
			S[i] = S[i-1] + D[i];
			D[i] = D[i] % 9901;
			S[i] = S[i] % 9901;
		}
		System.out.println(S[N]);
		
	}

}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 2309  (0) 2021.09.16
백준 17404  (0) 2021.09.15
백준 2133  (0) 2021.09.13
백준 13398  (0) 2021.09.09
백준 11055  (0) 2021.09.09