3247. 奇数和子序列的数量
这题是一道典型的排列组合题,直接模拟偶数和奇数的组合即可
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