I'm not a python guy, so the following code might seem not that "python style", but the algorithm should be ok.
#test input. the matrix can be any n * n size.
matrix = [[6,7,6],[4.5,6,6.75],[6,7.5,9]]
#assistant array to track which numbers we have already used.
#check[i] = 1 if i has been used
check = [0]* len(matrix)
#max sum
max_sum = 0
def getMax(matrix,check,row,curr_sum):
global max_sum
#base case, we have reached the last letter.
#check to see if this combination is max
if(row==len(matrix)-1):
for i in range(len(check)):
if(check[i]==0 and (matrix[row][i]+curr_sum)>max_sum):
max_sum = matrix[row][i]+curr_sum
#recursive case, pick the current available number, go to next letter.
else:
for i in range(len(check)):
if(check[i]==0):
check[i]=1
getMax(matrix,check,row+1,curr_sum+matrix[row][i])
check[i]=0
getMax(matrix,check,0,0)
print max_sum
Note that it's a sort of brute force algorithm using recursion. In terms of time-complexity, better algorithm (e.g. dynamic programming approach) exists. You can add cache to the method to improve efficiency.
Also, if you want to know the combination, we need extra efforts to track the combination. (e.g. using another matrix to record)
1B + 2C + 3C = 22.75?