迭代/递归问题?
我正在开发一个程序,其中有两个二维数组。一种称为男性,一种称为女性。它们都是 3x3 尺寸。该数组包含一个人喜欢另一个人的分数。
即(男性数组)这意味着male0喜欢female0 8,male0喜欢female1 5,male0喜欢female2 8,male1喜欢female0 9,male1喜欢female1 5,依此类推......
8 5 8
9 5 7
5 6 8
我还有另一个像这样的女性数组,其中他们对男性进行评分。
然后制作另一个二维数组,在其中添加每个女性(i,j)和男性(i,j)的分数,
如何找出哪个组合给出最大的总分数? 我想想出类似的东西
Best combination is:
male0 -> female2
male1 -> female0
male2 -> female1
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是尝试女性数组的每个排列,为每个排列找到总分,并最终选择给出最高分数的排列。
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.
这是稳定婚姻问题
This is the Stable Marriage Problem