题解 | 牛牛的括号式
牛牛的括号式
https://www.nowcoder.com/practice/59e373e519db4c8d86e10eab6b334cfb
考核知识点:数论、思维
将问题转化为:从N个括号中选择一个括号的x项,其余N-1个括号选择常数项,然后将所有这些组合的乘积求和。实现上,通过预处理后缀积和后缀符号,可以在O(N)的时间复杂度内完成计算
d = input()[1:-1].split(")(")
n = list(map(lambda x: int(x[1:]), d))
t = 1
for k in n:
t *= k
res = 0
for k in n:
res += t // k
print(int(res) % 10007)
查看1道真题和解析