지구정복

[DP] 백준 - 2Xn 타일링 본문

데이터 엔지니어링 정복/Algorithm

[DP] 백준 - 2Xn 타일링

nooh._.jl 2021. 7. 13. 19:24
728x90
반응형

-자바

package dp;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Tiling2xn {
	private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	private static int n;	//가로길이
	private static int[] d;	//dp배열
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt( br.readLine() );
		
		d = new int[n+1];
		d[0] = 1;
		d[1] = 1;
		
		for( int i=2; i<=n; i++ ) d[i] = ( d[i-2] + d[i-1] ) % 10007;

		bw.write( d[n] + "\n" );
		bw.flush();
		
		bw.close();
		br.close();
	}
}

 

-파이썬

n = int( input() )
d = [0] * (n+1)

d[0] = 1
d[1] = 1

for i in range( 2, n+1 ):
    d[i] = ( d[i-2] + d[i-1] ) % 10007
    
print( d[n] )
728x90
반응형
Comments