AcWing 1309. 车的放置(Python)
原题链接
中等
作者:
习学学
,
2021-02-22 23:55:57
,
所有人可见
,
阅读 372
Python 代码
a, b, c, d, k = map(int, input().split())
N = 2010
res = 0
mod = 100003
fact = [0] * N
infact = [0] * N
def qmi(a, b, p):
res = 1
while b:
if b & 1:
res = res * a % p
a = a * a % p
b >>= 1
return res
fact[0] = 1
infact[0] = 1
for i in range(1, N):
fact[i] = fact[i-1] * i % mod
infact[i] = infact[i-1] * qmi(i, mod-2, mod) % mod
def C(a, b):
global mod
return fact[a] * (infact[b] * infact[a-b] % mod) % mod
def A(a, b):
global mod
return fact[a] * infact[a-b] % mod
for i in range(k+1):
if i > min(a, b): break
if k - i > min(a+c-i, d): continue
res = (res + (C(a, i) * A(b, i) % mod) * (C(a+c-i, k-i) * A(d, k-i) % mod)) % mod
print(res)
py自带高精度呀