티스토리 뷰
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
|
import java.io.*;
public class boj_11729 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws IOException {
int n = Integer.parseInt(br.readLine());
hanoi(1, 3, n);
System.out.println((int) (Math.pow(2, n) - 1));
System.out.println(sb.toString());
}
public static void hanoi(int from, int to, int n) {
if (n == 1) {
sb.append(from + " " + to + "\n");
return;
}
hanoi(from, 6-from-to, n-1);
sb.append(from + " " + to + "\n");
hanoi(6-from-to, to, n-1);
}
}
|
cs |
- 재귀 너무 어렵다.
- 하노이의 탑 원판 총 이동횟수 : 2^N - 1
'PS > boj' 카테고리의 다른 글
boj)17478 - 재귀함수가 뭔가요? (0) | 2020.11.12 |
---|---|
boj)1074 - Z (0) | 2020.11.12 |
boj)2589 - 보물섬 (0) | 2020.11.11 |
boj)2941 - 크로아티아 알파벳 (0) | 2020.11.05 |
boj)1316 - 그룹 단어 체커 (0) | 2020.11.05 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 프로그래머스
- ㅇㄷㅇㅈ
- js array
- java
- 백기선 스터디
- js api
- js promise
- dreamcoding
- 백준
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- 프로그래머스 SQL
- 이펙티브자바 스터디
- HTTP 완벽가이드
- BOJ
- 김영한 JPA
- HTTP 완벽 가이드
- 드림코딩
- 패스트캠퍼스 컴퓨터공학 완주반
- GCP
- REST API
- 김영한 http
- Spring Security
- JPA 연관관계 매핑
- 이펙티브자바 아이템59
- 킹수빈닷컴
- http
- 이펙티브자바 아이템60
- 이펙티브자바
- 모던자바스크립트
- JS 딥다이브
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함