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
- Pizza Problem
- Fibonacci problem (Value of Fib(N)*Fib(N) - Fib(N-1) * Fib(N+1))
- Tiling Problem
- Frobenius coin problem
- The Lazy Caterer's Problem
- Josephus Problem Using Bit Magic
- Josephus problem | Set 1 (A O(n) Solution)
- Problem of 8 Neighbours of an element in a 2-D Matrix
- The Knight's tour problem | Backtracking-1
- Hungarian Algorithm for Assignment Problem | Set 1 (Introduction)
- Count number of triplets with product equal to given number with duplicates allowed
- Count number of trailing zeros in Binary representation of a number using Bitset
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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