解题思路:广度搜索。每搜索一个,要把他所有连接的点放进列表,为避免重复,该点不被记录
import numpy as np
w , l = input().split(' ')
w ,l = int(w), int(l)
in_list = np.zeros(shape=[w,l])
for i in range(w):
value = input().split(' ')
for j in range(l):
in_list[i][j] = int(value[j])
queue,all_list = [],[]
def get_sum(in_list,i,j,m,n):
queue,sum_list,in_list[i][j]=[[i,j]],in_list[i][j],0
while queue:
i, j = queue[0][0],queue[0][1]
if i>0 and j>0 and in_list[i-1][j-1] != 0:#左上
queue.append([i-1,j-1])
sum_list = sum_list + in_list[i-1][j-1]
in_list[i-1][j-1] = 0
if i>0 and in_list[i-1]