Arrange pairs of numbers so that members of adjacent pairs are equal

前端 未结 5 1141
北海茫月
北海茫月 2021-01-01 17:38

I would like to arrange the following items, forming the longest chain possible starting with 12-8 and matching the numbers end to end.

My items are 7-4, 11-8, 11-11

5条回答
  •  一整个雨季
    2021-01-01 18:25

    Think of the numbers as vertices and the pairs as edges of a graph (so there may be some multi-edges). Now your problem is reduced to finding the longest path in the graph where vertices (but not edges) may be repeated.

提交回复
热议问题