AcWing 1018. 最低通行费python版
原题链接
简单
作者:
小沈____
,
2020-01-25 19:49:15
,
所有人可见
,
阅读 828
题目描述 python版的,刚开始练习 不是很娴熟~希望多多指正!
python 代码
萌新写法
import sys
gird = []
for line in sys.stdin:
gird.append((line.split()))
n = int((gird.pop(0))[0])
gird = [[int(gird[j][i]) for i in range(len(gird[0]))] for j in range(len(gird))]
row = len(gird)
col = len(gird[0])
dp = [[0]*col for _ in range(row)]
dp[0][0] = gird[0][0]
for i in range(1,row):
dp[0][i] = dp[0][i-1] + gird[0][i]
for j in range(1,col):
dp[j][0] = dp[j-1][0] + gird[j][0]
for i in range(1,row):
for j in range(1,col):
dp[i][j] = min(dp[i-1][j],dp[i][j-1]) + gird[i][j]
print(dp[-1][-1])