Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Camera Movement
- Unity IAP
- Digital Ocean
- SDK upgrade
- MySQL
- linux
- Git
- Spring Boot
- nodejs
- Google Refund
- Packet Network
- docker
- springboot
- express
- OverTheWire
- css framework
- draganddrop
- Camera Zoom
- --watch
- react
- rpg server
- Unity Editor
- Google Developer API
- spread 연산자
- mongoDB
- screencapture
- java
- unity
- critical rendering path
- server
Archives
- Today
- Total
우당탕탕 개발일지
[프로그래머스] Level 2. 2 x n 타일링 본문
https://school.programmers.co.kr/learn/courses/30/lessons/12900
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
해결방법
동적계획법으로 푼다. N길이의 타일을 길이가 1인타일과 길이가 2인 타일을 적절히 조합하여 놓는 경우의 수를 구하는 문제이다. N길이의 타일을 까는 방법은 2가지가 있다.
- N-1 길이까지 타일을 깐다음 세로타일깔기.
- N-2 길이까지 타일을 깐다음 가로타일깔기.
따라서 f(n) = f(n-1) + f(n-2) 라는 결과가 나오게된다.
#include <string>
#include <vector>
using namespace std;
int solution(int n) {
if(n == 1) return 1;
if(n == 2 ) return 2;
int a = 1;
int b = 2;
for(int i= 3; i<=n; i++){
int val = (a+b)%1000000007;
a= b;
b = val;
}
return b;
}
아~ 동적계획법 정말 생각해내기 힘들어. ㅠㅠ
'Algorithm(c++) > Level 2' 카테고리의 다른 글
[프로그래머스] Level 2. 거리두기 확인하기 (0) | 2025.03.07 |
---|---|
[프로그래머스] Level 2. 2개 이하로 다른 비트 (0) | 2025.02.26 |
[프로그래머스] Level 2. 땅따먹기 (0) | 2025.02.24 |
[프로그래머스] Level 2. 모음사전 (0) | 2025.02.22 |
[프로그래머스] Level 2. 뉴스 클러스터링 (0) | 2025.02.21 |