| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 영어원서읽기
- 쓰릴오브파이트
- FIT XR
- 30분
- Writing
- 개발자
- 영어공부
- 매일
- 스탭퍼
- leetcode
- 링피트
- 리얼 클래스
- Problem Solving
- 뭐든
- 사이드
- 화상영어
- 미드시청
- 월간
- Daily Challenge
- 프로젝트
- realclass
- 만화도
- 3줄정리
- 파비최
- 괜찮음
- English
- 10분
- 읽기
- 잡생각
- 운동
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.11.27 Today's Challenge 본문
https://leetcode.com/problems/knight-dialer/
Knight Dialer - LeetCode
Can you solve this real interview question? Knight Dialer - The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L)
leetcode.com
DP로 푸는 문제
class Solution:
def knightDialer(self, n: int) -> int:
@cache
def dp(remain, square):
if remain == 0:
return 1
ans = 0
for next_square in jumps[square]:
ans = (ans + dp(remain - 1, next_square)) % MOD
return ans
jumps = [
[4, 6],
[6, 8],
[7, 9],
[4, 8],
[3, 9, 0],
[],
[1, 7, 0],
[2, 6],
[1, 3],
[2, 4]
]
ans = 0
MOD = 10 ** 9 + 7
for square in range(10):
ans = (ans + dp(n-1, square)) % MOD
return ans반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.11.29 Today's Challenge (0) | 2023.11.29 |
|---|---|
| 2023.11.28 Today's Challenge (0) | 2023.11.28 |
| 2023.11.26 Today's Challenge (0) | 2023.11.26 |
| 2023.11.25 Today's Challenge (2) | 2023.11.25 |
| 2023.11.24 Today's Challenge (1) | 2023.11.24 |
Comments