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

Автор bhuvnesh97, история, 6 лет назад, По-английски

I just find this problem but couldn't think of a solution ??can anyone will help me??

given N and K (2 <= N,K <= 8) and an array consisting of N distinct elements; in one move you can pick a block of K elements in the array and reverse the order, for example: if N = 5 and K = 3 and the array is [4 5 1 2 3], in one move you can make the array [1 5 4 2 3] or [4 2 1 5 3] or [4 5 3 2 1]. how many minimum number of moves is required to make the array sorted in ascending order?, if impossible, print -1.

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

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

as $$$N$$$ and $$$K$$$ are really small you can just enumerate all permutations and build a graph based on that (a permutation is a vertex and two permutations are conected by an edge if they can be tranformed into each other). The answere can then be found with bfs.