Program to find all possible permutations in which ‘n’ people can occupy ‘r’ seats in a theatre is discussed here.
N friends are planning to go to a movie. One among them suggested a few movies and all the others started to discuss and finally they selected a movie. One among them quickly booked their tickets online, but to their surprise, they were unable to select their seats. All of them got confused. Then anyhow, decided to go to the movie. They rushed to reach the theatre on time. Again they are surprised that no one was there in the theatre. They are the only people about to watch the movie. There is ‘r’ number of seats in which, ‘n’ number persons should sit. In how many ways they can sit inside the theatre?
Given the number of people ‘n’ and the number of seats ‘r’ as input. The task is to find the different number of ways in which ‘n’ number of people can be seated in those ‘r’ number of seats.
For example,
Input:
Number of people: 5
Number of Rows: 3
Output:
The total number of ways in which ‘n’ people can be seated in ‘r’ seats = 60.
Calculation:
P(n,r) =P(5,3)
=5! /(5?3)! = 5! / ( 5 ? 3 )!
= 120 / 2 = 60
The program to find all possible permutations in which n people can occupy r seats in a theatre is given below.
@@coding::1@@
Time complexity: O(n)