feat: added alternative python solutions.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -43,7 +43,7 @@
|
||||
},
|
||||
"solutions": {
|
||||
"main-ac": "ac.cpp",
|
||||
"alternative-ac": [],
|
||||
"alternative-ac": ["alternative-ac.py"],
|
||||
"wrong-answer": [],
|
||||
"time-limit": [],
|
||||
"time-limit-or-ac": [],
|
||||
|
||||
23
min-sum-path-2d/src/alternative-ac.py
Normal file
23
min-sum-path-2d/src/alternative-ac.py
Normal file
@@ -0,0 +1,23 @@
|
||||
n, m = map(int, input().split())
|
||||
grid = []
|
||||
for _ in range(n):
|
||||
row = list(map(int, input().split()))
|
||||
grid.append(row)
|
||||
|
||||
dp = [[0] * m for _ in range(n)]
|
||||
|
||||
dp[0][0] = grid[0][0]
|
||||
|
||||
for i in range(n):
|
||||
for j in range(m):
|
||||
if i == 0 and j == 0:
|
||||
continue
|
||||
|
||||
if i == 0:
|
||||
dp[i][j] = dp[i][j - 1] + grid[i][j]
|
||||
elif j == 0:
|
||||
dp[i][j] = dp[i - 1][j] + grid[i][j]
|
||||
else:
|
||||
dp[i][j] = grid[i][j] + min(dp[i - 1][j], dp[i][j - 1])
|
||||
|
||||
print(dp[n - 1][m - 1])
|
||||
Reference in New Issue
Block a user