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
- deep voice
- 한국어 tts
- 학습
- waveglow
- you only look once
- 딥러닝 보코더
- YOLO
- 딥러닝
- 노래합성
- 윈도우
- tacotron
- 타코트론
- 딥러닝 음성 합성
- 보코더
- Vocoder
- 트레이닝
- 한국어 음성 합성
- korean tts
- 음성 합성
- text-to-speech
- DCTTS
- singing voice synthesis
- melgan
- TTS
Archives
- Today
- Total
chldkato
백준 2186 문자판 (파이썬) 본문
https://www.acmicpc.net/problem/2186
2186번: 문자판
첫째 줄에 N(1 ≤ N ≤ 100), M(1 ≤ M ≤ 100), K(1 ≤ K ≤ 5)가 주어진다. 다음 N개의 줄에는 M개의 알파벳 대문자가 주어지는데, 이는 N×M 크기의 문자판을 나타낸다. 다음 줄에는 1자 이상 80자 이하의 영단어가 주어진다. 모든 문자들은 알파벳 대문자이며, 공백 없이 주어진다.
www.acmicpc.net
dfs + 메모이제이션로 구현하면 된다
1. word에 문자열을 단어로 나눠서 저장하고 start에 시작점이 될 후보를 저장한다
2. start에 있는 좌표를 하나씩 불러와서 dfs를 실행한다
3. idx를 증가시키면서 word 순서대로 이동할 수 있는지 확인한다
4. idx가 word 리스트 길이와 같으면 문자열을 완성했으므로 1을 return하여 가능한 경우의 수를 증가시킨다
import sys
input = sys.stdin.readline
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
def dfs(x, y, idx):
if idx == len(word):
return 1
if c[x][y][idx] != -1:
return c[x][y][idx]
c[x][y][idx] = 0
for i in range(4):
temp_x, temp_y = x, y
for _ in range(k):
nx = temp_x + dx[i]
ny = temp_y + dy[i]
if 0 <= nx < n and 0 <= ny < m:
if a[nx][ny] == word[idx]:
c[x][y][idx] += dfs(nx, ny, idx+1)
temp_x, temp_y = nx, ny
return c[x][y][idx]
n, m, k = map(int, input().split())
a = []
for _ in range(n):
a.append(list(input().strip()))
word = list(input().strip())
start = []
for i in range(n):
for j in range(m):
if a[i][j] == word[0]:
start.append([i, j])
ans = 0
c = [[[-1] * len(word) for _ in range(m)] for _ in range(n)]
for i in range(len(start)):
x, y = start[i]
ans += dfs(x, y, 1)
print(ans)
'백준' 카테고리의 다른 글
백준 5373 큐빙 (파이썬) (0) | 2020.04.14 |
---|---|
백준 5213 과외맨 (파이썬) (0) | 2020.04.12 |
백준 3108 로고 (파이썬) (4) | 2020.04.09 |
백준 15653 구슬 탈출 4 (파이썬) (0) | 2020.03.10 |
백준 15644 구슬 탈출 3 (파이썬) (0) | 2020.03.10 |
Comments