Algorithm for Human Towering

后端 未结 4 1906
悲哀的现实
悲哀的现实 2021-01-02 22:39

In Cracking the Coding Interview, Fourth Edition, there is such a problem:

A circus is designing a tower routine consisting of people standing atop

4条回答
  •  天涯浪人
    2021-01-02 22:48

    For example

    (3,2) (5,9) (6,7) (7,8)

    Obviously, (6,7) is an unfit item, but how about (7,8)?

    In answer to your Question - the algorithm first runs starting with 3,2 and gets the sequence (3,2) (5,9) marking (6,7) and (7,8) as unfit.

    It then starts again on (6,7) (the first unfit) and gets (6,7) (7,8), and that makes the answer 2. Since there are no more "unfit" items, the sequence terminates with maximum length 2.

提交回复
热议问题