Skip to content

Commit 8d0af94

Browse files
Merge pull request #1694 from CodingTestStudy2/최원준
[최원준] Day22
2 parents c361043 + f1e3dd2 commit 8d0af94

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
3+
'''
4+
1. 아이디어 :
5+
-
6+
7+
2. 시간복잡도 :
8+
O(n)
9+
10+
3. 자료구조/알고리즘 :
11+
-
12+
13+
'''
14+
15+
class Solution:
16+
def findDegrees(self, matrix: list[list[int]]) -> list[int]:
17+
return [sum(m) for m in matrix]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
3+
'''
4+
1. 아이디어 :
5+
-
6+
7+
2. 시간복잡도 :
8+
O(maxMove * n * m * 4)
9+
10+
3. 자료구조/알고리즘 :
11+
dp
12+
13+
'''
14+
class Solution:
15+
def findPaths(self, m: int, n: int, maxMove: int, startRow: int, startColumn: int) -> int:
16+
MOD = 1_000_000_009
17+
18+
dp = [[0] * n for _ in range(m)]
19+
dp[startRow][startColumn] = 1
20+
21+
ans = 0
22+
dir = [0,1],[0,-1],[-1,0],[1,0]
23+
24+
for _ in range(maxMove):
25+
next_dp = [[0] * n for _ in range(m)]
26+
27+
for row in range(m):
28+
for col in range(n):
29+
if dp[row][col] == 0:
30+
continue
31+
32+
for dx, dy in dir:
33+
next_row = row + dx
34+
next_col = col + dy
35+
36+
if 0<=next_row<m and 0<=next_col<n:
37+
next_dp[next_row][next_col] += dp[row][col]
38+
next_dp[next_row][next_col] %= MOD
39+
else:
40+
ans += dp[row][col]
41+
ans %= MOD
42+
dp = next_dp
43+
44+
return ans

0 commit comments

Comments
 (0)