반응형
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 |
Tags
- 비제차 상미분 방정식
- SW역량테스트
- 스피치 연습
- Problem set 2.7
- 삼성SW역량테스트
- Advanced Engineering Mathematics
- 미방
- Ode
- Problem set 1.5
- 미분방정식
- ODEs
- Python
- 공수
- 백준
- 공수1
- 영어회화
- Homogeneous ODEs
- Problem Set 1.4
- kreyszig
- vocabulary
- English
- homogeneous
- Nonhomogeneous ODEs
- 코딩테스트
- Conversation
- 공학수학
- 공수 문제풀이
- 공업수학
- speech
- 문제풀이
Archives
- Today
- Total
한걸음
백준 2210 : 숫자판 점프 본문
반응형
https://www.acmicpc.net/problem/2210
2210번: 숫자판 점프
111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111, 121112, 121211, 121212, 211111, 211121, 212111, 212121 이 가능한 경우들이다.
www.acmicpc.net
https://github.com/HPYoo/swcodingtest/commit/0a383076f742250287f370ff099159bef6acb04c
sw coding 2210 update(Baekjoon) · HPYoo/swcodingtest@0a38307
Showing 1 changed file with 28 additions and 0 deletions.
github.com
1. 배열 사이즈가 작아 BFS로도 풀이가 가능
BFS사용에 익숙해지니까 왠만한 문제를 BFS로 해결한다.
큐에 넣고 반복문 돌릴 때 내가 만들어둔 숫자 조합 리스트에서 비교하고, 없으면 추가하며 큐가 점차 빠지도록 만들어주면 된다.
2. 전체코드
메모리 : 115164 KB, 시간 : 232 ms, 풀이 시간 : 15min
board = [list(map(int, input().split())) for _ in range(5)]
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
def bfs():
arr = []
for i in range(5):
for j in range(5):
q = [[i, j, 1, str(board[i][j])]]
while q :
x, y, cnt, string = q[0]
del q[0]
if cnt == 6 :
if string in arr :
continue
else :
arr.append(string)
continue
for d in range(4):
nx = x + dx[d]
ny = y + dy[d]
if 0 <= nx < 5 and 0 <= ny < 5 :
q.append([nx, ny, cnt + 1, string + str(board[nx][ny])])
return arr
result = bfs()
print(len(result))
반응형
'Coding Test' 카테고리의 다른 글
백준 23291 : 어항 정리 (3) | 2023.12.18 |
---|---|
백준 1941 : 소문난 칠공주(Python) (2) | 2023.12.11 |
백준 1986 : 체스 (1) | 2023.12.05 |
백준 7562 : 나이트의 이동 (1) | 2023.12.04 |
백준 2234 : 성곽 (3) | 2023.11.29 |