Encountered a permutation of the following problems, did not calculate their own, and finally in Python in the permutation library function to obtain the answer. The total number of 10-bit students should be 10!. However, it is not clear how the number of male students at any time in the car is less than the number of female students. But it can be calculated using the following code.
Use the Python3 program to find the answers for the library combinations and permutations functions that have permutations in the A:python. 1 from itertools import permutations 2 res=0 3 s=[ 1,1,1,1,1,2,2,2,2,2] # 1 means boys, 2 Menas girls 4 for item in Permutations (s,10): 5 for i in range (1,10): 6 if not Item[:i].count (1) >=item[:i].count (2): 7 break 8 else: 9 res+=1  10 print ("The num is {}". Format (res)) [email protected]:~# python3 permutation_girls_boys.pythe num is 604800
Using Python to solve permutation and composition problems