반응형

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public void solution() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] dp = new int[n+2]; dp[0] = 0; dp[1] = 1; dp[2] = 3; for(int i=3; i<=n; i++){ dp[i] = (dp[i-1]+dp[i-2]+dp[i-2])%10007; } System.out.println(dp[n]); } public static void main(String args[]) throws IOException { new Main().solution(); } }
백준 11726번 2xn 타일링 (https://mokggang.tistory.com/42) 두 번째 문제다.
2x2 크기의 타일은 1x2 타일 2개로 변경이 가능하기 때문에 dp[i-2]를 추가해준다.
(2x1 의 타일의 경우 중복되기 때문에 갯수가 추가되지 않는다)
반응형
'개발 > 알고리즘' 카테고리의 다른 글
백준 16194번 : 카드 구매하기 2 (0) | 2023.02.02 |
---|---|
백준 11052번 : 카드 구매하기 (0) | 2023.02.02 |
백준 11726번 : 2xn 타일링 (0) | 2023.01.27 |
백준 1463번 : 1로 만들기 (0) | 2023.01.27 |
백준 1182번 : 부분수열의 합 (0) | 2023.01.26 |