views:

48

answers:

2

I am working on a program where I have two 2d arrays. one is called males and one females. they're both 3x3 size. The array contains a score of how much a person likes the other.

i.e. (male array) This means that male0 likes female0 8, male0 likes female1 5, male0 likes female2 8, male1 likes female0 9, male1 likes female1 5, and so on....

    8 5 8
    9 5 7
    5 6 8

I also have another array like this for females where they rate the males.

Then a make another 2d array where I add the scores for each female(i,j) and male(i,j)

How do I go about finding out which combination gives the biggest total score? I would like to come up with something like

Best combination is:
male0 -> female2
male1 -> female0
male2 -> female1
+2  A: 

One way is to try every permutation of a female array, for each permutation finding the total score, and in the end picking the permutation that gives the highest score.

Reinderien
I agree. There are six ways to pair the men with the women (in this case), so it would be reasonably quick. If I'm not mistaken, this is the most efficient general approach, too. (Saving off scores for each pair will help speed it up in larger cases, but it's still an O(n!) problem.)
JoshD
+2  A: 

This is the Stable Marriage Problem

McTrafik
"Maximum weighted matchings do not have to be stable, but in some applications a maximum weighted matching is better than a stable one."
ide