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?
Examples –
Input : n = 12, s = 4 Output : 126 Input : n = 16, s = 5 Output : 792
# Python code to calculate number # of ways of selecting \'p\' non # consecutive stations out of # \'n\' stations def stopping_station( p, n): num = 1 dem = 1 s = p # selecting \'s\' positions # out of \'n-s+1\' while p != 1: dem *= p p-=1 t = n - s + 1 while t != (n-2 * s + 1): num *= t t-=1 if (n - s + 1) >= s: return int(num/dem) else: # if conditions does not # satisfy of combinatorics return -1 # driver code num = stopping_station(4, 12) if num != -1: print(num) else: print("Not Possible") # This code is contributed by "Abhishek Sharma 44" |
chevron_right
filter_none
Output :
126
Please refer complete article on Number of stopping station problem for more details!
Recommended Posts:
- Python Program to print digit pattern
- Python | Extract key-value of dictionary in variables
- Python program to convert time from 12 hour to 24 hour format
- Google Chrome Dino Bot using Image Recognition | Python
- Python | Use of __slots__
- Python - Summation of float string list
- Python | Animated Banner showing 'GeeksForGeeks'
- Python | Segregate list elements by Suffix
- Python Program for Selection Sort
- Python Program for Bubble Sort
- Python Program for Insertion Sort
- Python Program for Heap Sort
- Python Program for Counting Sort
- Python Program for Radix Sort
- Python Program for n-th Fibonacci number
- Python Program for Counting Sort
- Python Program for ShellSort
- Python Program for Longest Common Subsequence
- Python Program for Binary Search (Recursive and Iterative)
- Python Program for 0-1 Knapsack Problem

