Блог пользователя dingshu

Автор dingshu, 14 лет назад, По-английски

Let's divide this queue into to 2 parts: 1... k and k + 1... n.

It's obvious that pi ≤ k while i ≤ k, pi > k while i > k.

So the answer to the part of pk + 1... n is (n - k)n - k.

Image a tree with k vertexes. The number of those trees is kk - 2. (Cayley trees)

Choose a vertex to be root, there are k ways.

Set pi = fatheri in the tree. And for the root, set proot = 1.

It's easy to find p1... k satisfied the problem.

So answer is kk - 1(n - k)n - k.

  • Проголосовать: нравится
  • +14
  • Проголосовать: не нравится

»
14 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +3 Проголосовать: не нравится

Maybe kk - 1(n - k)n - k?

ADD: It's OK now.

»
14 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Because k <= 8, it could be solved by backtrack too.

»
14 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i cann't understand the k^(k-1) ?? if input is 3 3 so all of the number are e.g:(p1,p2,p3),(2,1,1),(2,3,1),(3,2,1),(3,3,1),(3,1,1). can you tell me some else?