扩展:这个问题我认为是多数组组合问题。
《多个数组,每个数组中选择一项,总共能有多少种组合,reduce函数实现》
《多个数组,每个数组中选择一项,总共能有多少种组合,treelib实现》
通过代码算出来,并没有遍历全部路径
import numpy as np
import copy
#这个函数的作用是多个数组,每个数组中取一个数字,最多能有多少种组合方式。
def getAllPossibleMap(mList):
H = len(mList)
W = 1
for l in mList:
W = W * len(l)
print('getAllPossibleMap : ', H, W)
mat = np.zeros((H, W), dtype=np.int8)
for i in range(H):
for j in range(W):
step = W // (pow(len(mList[i]), i) * len(mList[i]))
mat[i, j] = mList[i][(j // step) % len(mList[i])]
return mat
def printMat(mat):
print('-------