3247. 奇數(shù)和子序列的數(shù)量
這題是一道典型的排列組合題奔缠,直接模擬偶數(shù)和奇數(shù)的組合即可
class Solution:
def subsequenceCount(self, nums: List[int]) -> int:
a,b = 0,0
for it in nums:
if it%2 == 0:
a += 1
else:
b += 1
if b == 0:
return 0
ans1 = [a]
t = (10**9+7)
for i in range(1,a+1):
ans1.append(ans1[-1]*(a-i)//(i+1))
ans2 = [b]
for y in range(3,b+1,2):
ans2.append(ans2[-1]*(b-y+2)*(b-y+1)//(y*(y-1)))
return ((sum(ans1)+1)%t)*((sum(ans2))%t)%t