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

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

We are given a sequence : [1,2,...N]. Lets consider all the permutations of the above sequence. Now, a good permutation is defined as the one in which there is atleast one pair of numbers such that a[i]+1=a[i+1]. How to count the number of good permutations ? This problem is from some old contest.

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

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

can you give the problem link plz

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится
Hint 1
Hint 2
Hint 3
  • »
    »
    7 лет назад, скрыть # ^ |
    Rev. 5  
    Проголосовать: нравится 0 Проголосовать: не нравится

    I have a doubt : how can we be sure that permutations from (n-1)f_n-1 and (n-2)f_n-2 will not repeat.

    example let say we need f_5
    Now, one of the possible solution of f_4 be {3, 2, 1, 4}
    from this we will have more (n-1) permutations for f_5 , which are:
    {3, 2, 1, 5, 4} , {3, 2, 5, 1, 4}, so on..

    and let one of the possible solution of f_3 be {3, 2, 1}
    than new (n-2) solution for f_5 generated from this would be:
    {3, 2, 1, 5, 4}, {3, 2, 5, 4, 1} , so on..
    but they are counting the same permutations {3, 2, 1, 5, 4}
    Please help if i am wrong.