I have problem which requires me to compare all children of two nodes of general tree. Each parent can have multiple children, for each comparison I have to get best possible combination. For example if I wanted to compare nodes B and F possible combinations of children are: C:G, C:H, D:G, D:H, E:G, E:H.
For each pair I have result data that is stored in arrays:
[[2,0], [[C:G,C:H],
[3,5], = [D:G,D:H],
[2,3]] [E:G,E:H]]
I tried brute force algorithm similar to this one: https://www.geeksforgeeks.org/combinations-from-n-arrays-picking-one-element-from-each-array/ but this solution allows best combination to be one, where one node is paired multiple times with node from other tree.
In case of comparison 3x3 nodes possible solutions are:
Matrix of possible pairs values:
[[1,0,1],
[0,2,1],
[1,1,0]]
Possible combinations with results:
[0,0],[1,1],[2,2] = 3
[0,0],[1,2],[2,1] = 3
[0,1],[1,0],[2,2] = 2
[0,1],[1,2],[2,0] = 0
[0,2],[1,1],[2,0] = 4
[0,2],[1,0],[2,1] = 2
I wonder should I use that matrix and if so, how to implement algorithm. I'm writing in C++ but it is part of uni assignment so I don't want ready code, just pseudo-code solution, or pointers to look in right direction. I cannot use library algorithm, or others. I have to implement solution myself. I was thinking about recursive function that passes all cells in column that were visited, but I think there is easier way to do that. I can use brute force approach, so I'm looking to calculate all possible combinations and pick best.