티스토리 뷰
문제: https://www.acmicpc.net/problem/11726(백준)
문제: https://programmers.co.kr/learn/courses/30/lessons/12900(프로그래머스)
11726번: 2×n 타일링
2×n 크기의 직사각형을 1×2, 2×1 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×5 크기의 직사각형을 채운 한 가지 방법의 예이다.
www.acmicpc.net
프로그래머스의 [멀리 뛰기] 문제와 사실상 같은 문제이다. 멀리 뛰기 게시글에 해당 내용을 정리 해 놓았다.
소스코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long[] answers = new long[n + 1];
answers[0] = 1;
answers[1] = 1;
for (int i = 2; i <= n; i++) {
answers[i] = (answers[i - 1] + answers[i - 2]) % 10_007;
}
System.out.println(answers[n]);
}
}
class Solution {
public int solution(int n) {
int[] answers = new int[n];
answers[0] = 1;
answers[1] = 2;
for (int i = 2; i < n; i++) {
answers[i] = (answers[i - 1] + answers[i - 2]) % 1000000007;
}
return answers[n - 1];
}
}
'알고리즘 문제 > 백준' 카테고리의 다른 글
[백준] 14719번문제. 빗물 - Java (0) | 2021.06.11 |
---|
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 탐욕법
- Sorting
- 코딩테스트
- 멀리 뛰기
- 큐
- Queue
- DP
- 동적계획법
- 완전탐색
- dfs
- 데브코스
- Heap
- 알고리즘
- 프로그래머스
- 자바
- 백준
- greedy
- BFS
- 자료구조
- Hash
- Algorithm
- 그래프
- dynamic programming
- 해시
- programmers
- 힙
- 연습문제
- java
- stack
- 정렬
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함