试题 算法训练 6-1 递归求二项式系数值

思路:把所有都变成C(k,k)或C(0,n)求和即可。

资源限制
时间限制:10.0s 内存限制:256.0MB
在这里插入图片描述
样例输入
一个满足题目要求的输入范例。
3 10
样例输出
与上面的样例输入对应的输出。

数据规模和约定
  输入数据中每一个数的范围。
  例:结果在int表示时不会溢出。

代码

nlist = list(map(int,input().split()))
a = nlist[0]
b = nlist[1]
def fun(n,s):
    if n==s or n == 0:
        return 1
    else:
        return fun(n,s-1) + fun(n-1,s-1)
c = fun(a,b)
print(c)
发布了81 篇原创文章 · 获赞 10 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Python_Matlab/article/details/105138402