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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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 )
- Fibonacci problem (Value of Fib(N)*Fib(N) - Fib(N-1) * Fib(N+1))
- 21 Matchsticks Problem
- Perfect Sum Problem
- Pizza Problem
- Tiling Problem
- Transportation Problem | Set 5 ( Unbalanced )
- The Lazy Caterer's Problem
- Cake Distribution Problem
- Transportation Problem | Set 1 (Introduction)
- Frobenius coin problem
- Josephus Problem Using Bit Magic
- Josephus problem | Set 1 (A O(n) Solution)
- C++ Program for the Fractional Knapsack Problem
- Problem of 8 Neighbours of an element in a 2-D Matrix
- Transportation Problem Set 8 | Transshipment Model-1
- The Knight's tour problem | Backtracking-1
Improved By : vt_m