[Stable marriage]

Source: Internet
Author: User
Tags sorts

Stable marriage is a problem in combination mathematics.

The problem is probably like this: there is a Community with N girls and N boys. Each girl sorts boys according to her preference, at the same time, each boy also sorts girls according to their preferred degree. Then match the N girls and N boys into a complete marriage.

If there are two girls a and B, two boys A and B, so that a and a get married, B and B get married, but a prefers B rather than a, B prefers a rather than B, then this marriage is unstable. A and B may be accompanied by others because they both believe that they prefer their new partners more than their current spouse.

If a complete marriage is not unstable, it is said to be stable. It is proved that every n female and N male community has a stable marriage. However, this situation only exists in societies of the opposite sex. That is to say, in the same-sex community, the existence of a stable marriage will no longer be guaranteed.

Gale-Shapley Algorithm

While there is a man m who is free and has not been married to every woman

Choose this man m
Make w the highest rank of Women in the priority list of M who have not yet been married
If W is free
(M, W) Changes to appointment status
Else W is currently dating M1
If W prefers M1 rather than m
M keep free
Else W prefers m rather than M1
(M, W) Changes to appointment status
M1 becomes free
Endif
Endif
Endwhile


Poj 3487

















Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.