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