227. How Many Orderings
Core1000 ms256 MBSolved by 0%
Print how many different orders n distinct items can be arranged in.
Reason about the choices. There are n items that could go first. Whichever
you pick, there are n-1 left for the second position, and so on. Multiplying
those choices together gives the answer.
This is the size of the search space every permutation-generating backtracking
program has to walk, which is why they become impossible so quickly: at
n = 20 there are more orderings than a computer could enumerate in a
lifetime.
Constraints - `1 ≤ n ≤ 20`
Input
A single line containing one integer n.
Output
Print one integer, the number of distinct orderings.
Input3
Output6
Noteis three items, whose six orderings you can list
Input1
Output1
Noteis one item with a single ordering
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution