Which algorithm could solve my wedding table issue?

后端 未结 4 821
无人共我
无人共我 2021-02-08 07:59

I have x guests for my wedding and y tables with z seats. Guest A can sit on the same table as guest B and guest C can not sit on the same table as guest D, ....

Given

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-08 08:24

    This problem is NP-hard in the general case, so you shouldn't expect to find a general solution to it that's efficient if the number of tables or guests is large. This problem is a variation on this earlier problem which asks about divvying people up into different houses based on their preferences, and you can reduce that problem (which is NP-hard) to this one by simply giving each table enough capacity to hold every single guest.

    If the number of people per table is small and the number of guests is small, you could just brute-force the solution by trying every possible assignment. Another option would be to try randomly guessing a few solutions and then incrementally modifying them to try to find a solution that works (for example, using a hill-climbing algorithm).

    Hope this helps!

提交回复
热议问题