There are 12 intermediate stations between two places A and B. Find the number of ways in which a train can be made to stop at 4 of these intermediate stations so that no two stopping stations are consecutive?
Input : n = 12, s = 4 Output : 126 Input : n = 16, s = 5 Output : 792
Explanation 1 :
Fix/remove of the four stops as fixed points and calculate in how many ways the other stations can be inserted between them, if you must have at least one station between stops.
A x x x x x x x x B
Between these 8 non-halting stations we have 9 places and we select these 9 places as halt between these 8 stations.
Therefore, answer should be = 126
Explanation 2 :
If you know about combinations about indistinguishable balls into distinguishable boxes, then you can simply use, . In this question, $n$ is number of stations and $p$ is number of stations on which you want to stop. Here stopping stations are as indistinguishable balls and non-stopping stations are as distinguishable boxes.
Therefore, = = 126
- Secretary Problem (A Optimal Stopping Problem)
- Find maximum distance between any city and station
- Maths behind number of paths in matrix problem
- Transportation Problem | Set 7 ( Degeneracy in Transportation Problem )
- 21 Matchsticks Problem
- Fibonacci problem (Value of Fib(N)*Fib(N) - Fib(N-1) * Fib(N+1))
- Pizza Problem
- Tiling Problem
- Frobenius coin problem
- The Lazy Caterer's Problem
- Cake Distribution Problem
- Josephus Problem Using Bit Magic
- Transportation Problem | Set 5 ( Unbalanced )
- Transportation Problem | Set 1 (Introduction)
- Josephus problem | Set 1 (A O(n) Solution)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : vt_m