We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
what, the Editorial is so greatful.But I think this problem is a combinatorics problem. And use inclusion-exclusion principle
let~s define var "all" be the number of the total number which occuer twice.
let`s define var ans be the total number of permutation of all the number. it can calc it A(n, n) / (all * 2!)
and now we use inclusion-exclusion principle.
for (k := 1 to all)
mean that there are k pair number break the problem condition
so we should add the number when k is even and cut the number when k is odd
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tara's Beautiful Permutations
You are viewing a single comment's thread. Return to all comments →
what, the Editorial is so greatful.But I think this problem is a combinatorics problem. And use inclusion-exclusion principle let~s define var "all" be the number of the total number which occuer twice. let`s define var ans be the total number of permutation of all the number. it can calc it A(n, n) / (all * 2!) and now we use inclusion-exclusion principle. for (k := 1 to all) mean that there are k pair number break the problem condition so we should add the number when k is even and cut the number when k is odd