Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c1ef9e8

Browse files
Iterables and Iterators
1 parent ebde783 commit c1ef9e8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Enter your code here. Read input from STDIN. Print output to STDOUT
2+
3+
import math
4+
import itertools
5+
6+
7+
def nCr(n, r):
8+
f = math.factorial
9+
return f(n) / f(r) / f(n - r)
10+
11+
12+
n = int(input())
13+
l = input().split()
14+
k = int(input())
15+
matchlst = list()
16+
for x in range(len(l)):
17+
if l[x] == 'a':
18+
matchlst.append(x + 1)
19+
c = 0
20+
newlst = (list(itertools.combinations(l, k)))
21+
for x in newlst:
22+
if 'a' in x:
23+
c += 1
24+
print(c / nCr(n, k))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /