We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Iterables and Iterators
Iterables and Iterators
Sort by
recency
|
907 Discussions
|
Please Login in order to post a comment
import itertools List=[] count = 0 n = int(input()) l = input().split(" ") k = int(input()) for i in range(len(l)): if(l[i]=="a"): List.append(i+1) comb = list(itertools.combinations([i+1 for i in range(len(l))],k)) for i in comb: for j in List: s="" if(j in i): s+=" " if(len(s)>=1): count+=1 break print(count/len(comb))
n = int(input()) # Length of the list letters = input().split() # List of letters k = int(input()) # Number of indices to select
comb = list(combinations(letters, k)) favorable = sum(1 for group in comb if 'a' in group) probability = favorable / len(comb) print(f"{probability:.3f}")