Home  >  Q&A  >  body text

java - 请问这种排列算法的难度在什么水平?

https://segmentfault.com/q/10... 这个问题中有四种对4位整型数组进行排列组合的算法,一个一个按照运行顺序写下来觉得很有意思,我肯定直接写不出来,想问一下算法界的大神们,这种算法大概是什么水平的?如果是很简单的那种,我大概真的要去补一下了...另外,除了死记硬背,这么刁钻的设计是怎么想出来的...

伊谢尔伦伊谢尔伦2744 days ago534

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 10:50:09

    The process of full arrangement can be regarded as a tree traversal process. Each leaf node is an arrangement. However, it should be noted that the edges of each subtree cannot overlap with the edges of the parent node.
    The tree traversal process is easy to handle, either recursively, using a stack or queue, or even setting up an array to save the state. The problem that the edges of the subtree cannot overlap with the edges of the parent node is also easy to handle. When traversing the subtree, only traverse available , and just mark it after traversing it.
    I think this problem is easier to solve if it is converted into a tree. It can be implemented in various ways.

    reply
    0
  • Cancelreply