Stable Marriage Problem

Problem:给出n个男人心中n个女人的排名,和n个女人心中n个男人的排名,求一种匹配使之形成稳定匹配。(稳定指的是形成的集合中,任意两对之间,不存在某个人和某个人在一起 比集合中的分配更优)

详见维基百科:Stable_marriage_problem

matrix67的分析非常有趣:matrix67 


Solution:

function stableMatching { 
    Initialize all m ∈ M and w ∈ W to free 
    whilefree man m who still has a woman w to propose to { 
       w = m's highest ranked such woman to whom he has not yet proposed 
       if w is free 
         (m, w) become engaged 
       else some pair (m', w) already exists 
         if w prefers m to m' 
           (m, w) become engaged 
           m' becomes free 
         else 
           (m', w) remain engaged 
    } 
} 


Think:这个算法中,man做的选择总是越来越差的,woman做的选择总是越来越好的。


Practice:

1.Hiring in Chefland (昨天晚上做比赛遇到的,现在好像还不能提交,目测应该能过)

Code:Hiring in Chefland.cpp


2.The Stable Marriage Problem

Code:poj3487.cpp


3.Marriage is Stable

p.s. woman 和 man 的名字可能相同

Code:zoj1576.cpp



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值