Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursion Help
#5
You don't need an array of size n!.

Define a table, like[x][y], as the likeability of woman x with man y, for x and y in [1..n]. Then make a list L = [1..n] representing the men, and recurse through all possible permutations of L. Each permutation P represents a pairing, where woman k is paired with man P[k].

One possible permutation algorithm is described here: http://www.bearcave.com/random_hacks/permute.html
Personally I think the second one is the simplest to understand. Essentially you call the recursive function with a sequence and a starting number "start". The subsequence consisting of the first "start" items constitute the part of the permutation that is already built. Then it loops through all the remaining permutations by calling itself once for each remaining item as the next item in the subsequence.

Instead of printing the output at the last level of recursion, call a function that loops through the permutation and sums the likeability of each pairing. Since woman k is paired with man P[k], this is the sum of like[k][P[k]] for all k in [1..n].
Reply


Messages In This Thread
Recursion Help - by Sivrat - 2010-09-28, 01:16 PM
Recursion Help - by Russt - 2010-09-28, 07:36 PM
Recursion Help - by Sivrat - 2010-09-28, 07:47 PM
Recursion Help - by Fiel - 2010-09-29, 01:02 AM
Recursion Help - by Russt - 2010-09-29, 01:35 AM
Recursion Help - by Fiel - 2010-09-29, 03:08 AM
Recursion Help - by Sivrat - 2010-09-29, 09:21 AM
Recursion Help - by Stereo - 2010-09-29, 12:42 PM
Recursion Help - by Sivrat - 2010-09-29, 06:38 PM
Recursion Help - by Sivrat - 2010-09-29, 08:35 PM
Recursion Help - by Stereo - 2010-09-29, 09:33 PM
Recursion Help - by Sivrat - 2010-09-30, 10:31 AM
Recursion Help - by Fiel - 2010-09-30, 11:29 AM
Recursion Help - by Sivrat - 2010-09-30, 11:49 AM
Recursion Help - by Fiel - 2010-09-30, 11:50 AM
Recursion Help - by Sivrat - 2010-09-30, 12:32 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)