티스토리 뷰
문제 링크
https://www.acmicpc.net/problem/11727
11727번: 2×n 타일링 2
2×n 직사각형을 1×2, 2×1과 2×2 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×17 직사각형을 채운 한가지 예이다.
www.acmicpc.net
이전 문제와 동일하게 규칙만 찾아내면 구현할 수 있습니다.


N이 1일때는 여전히 1가지 방법밖에 없지만 N이 2인경우 2x2 도형이 하나 추가되어 3가지 방법이 생깁니다.
N이 3 이후일때는
N-1 의 도형에서 오른쪽에 2x1 세로 도형이 한 개 붙은 형태와
N-2 의 도형에서 오른쪽에 1x2 가로 도형이 두 개 붙은 형태, 2x2 타일이 한 개 붙은 형태로 완성이 됩니다.
따라서 N은 dp(N-1) + dp(N-2) * 2 로 구할 수 있습니다.
구현 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#define endl '\n' | |
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr); | |
using namespace std; | |
const int MAX = 1001; | |
int d[MAX]; | |
int dp(int n){ | |
if(n==1) return 1; | |
if(n==2) return 3; | |
if(d[n] != 0) return d[n]; | |
return d[n] = (dp(n-2) * 2 + dp(n-1)) % 10007; | |
} | |
int main(){ | |
fastio; | |
int n; | |
cin >> n; | |
cout << dp(n) << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
d = [] | |
d.append(0) | |
d.append(1) | |
d.append(3) | |
for i in range(3,n+1): | |
d.append((d[i-1] + d[i-2] * 2) % 10007) | |
print(d[n]) |
'Coding Test > 백준' 카테고리의 다른 글
[C++/Python] 백준 10844 - 쉬운 계단 수 (0) | 2020.07.24 |
---|---|
[C++/Python] 백준 9095 - 1, 2, 3 더하기 (0) | 2020.07.23 |
[C++/Python] 백준 11726 - 2xn 타일링 (0) | 2020.07.21 |
[C++/Python] 백준 1463 - 1로 만들기 (0) | 2020.07.20 |
[C++/Python] 백준 13015 - 별찍기 - 23 (0) | 2020.07.17 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- pyspark
- Sqoop
- 하둡
- 분할정복
- Jaeha's Safe
- 2225
- 하이브
- C++
- 팰린드롬 구하기
- 백준
- 알고스팟
- 완전탐색
- 합친 lis
- 종만북
- python
- 코딩인터뷰 완전분석
- HDFS
- Django
- 배열과 문자열
- import
- 삼각형 위의 최대 경로 수 세기
- HiveQL
- 두니발 박사의 탈옥
- hive
- 삼각형 위의 최대 경로
- 스파크
- 외발 뛰기
- microwaving lunch boxes
- 출전 순서 정하기
- Hadoop
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함