def fac(n):
if n<2:
return 1
return n*fac(n-1)
def choose(n,r):
if r>n/2:
r=n-r
ans=1
for i in range(n,n-r,-1):
ans*=i
ans/=fac(r)
return ans
def Main():
t=int(input())
while t>0:
t-=1
n=int(input())
p=float(input())
q=1-p
pro=0
for i in range(n,2*n):
pro+=choose(2*n-1,i)*(p**i)*(q**(2*n-1-i))
print("%1.2f"%pro)
if __name__=='__main__':
Main()
if n<2:
return 1
return n*fac(n-1)
def choose(n,r):
if r>n/2:
r=n-r
ans=1
for i in range(n,n-r,-1):
ans*=i
ans/=fac(r)
return ans
def Main():
t=int(input())
while t>0:
t-=1
n=int(input())
p=float(input())
q=1-p
pro=0
for i in range(n,2*n):
pro+=choose(2*n-1,i)*(p**i)*(q**(2*n-1-i))
print("%1.2f"%pro)
if __name__=='__main__':
Main()
Comments
Post a Comment