python代码递归:您可以得到多少个编译数作为和,但我不知道';i don’我不知道如何打印这篇汇编
python代码递归:这段代码提供了您需要的编译次数 可以将数字作为列表的和(例如:n=4 list=[1,2]结果是5 但是我不知道我怎么能把这个汇编打印出来,任何人都可以 帮忙?(1+1+1+1,1+1+2,1+2+1,2+1+1,2+2)python代码递归:您可以得到多少个编译数作为和,但我不知道';i don’我不知道如何打印这篇汇编,python,python-3.x,list,recursion,sum,Python,Python 3.x,List,Recursion,Sum,python代码递归:这段代码提供了您需要的编译次数 可以将数字作为列表的和(例如:n=4 list=[1,2]结果是5 但是我不知道我怎么能把这个汇编打印出来,任何人都可以 帮忙?(1+1+1+1,1+1+2,1+2+1,2+1+1,2+2) def count_多次(n,lst): ''func计算我们能做多少组合'' 如果n==0: 返回1 如果n您可以在每次递归调用时存储当前编译,并且当您遇到基本情况时,即成功找到编译,则可以打印当前编译 def count_多次(n,lst,comp
def count_多次(n,lst):
''func计算我们能做多少组合''
如果n==0:
返回1
如果n您可以在每次递归调用时存储当前编译,并且当您遇到基本情况时,即成功找到编译,则可以打印当前编译
def count_多次(n,lst,compilation=[]):
''我们可以做多少组合''
如果n==0:
印刷(汇编)
返回1
如果nim在这里是新的,那么如果你能告诉我我如何将其标记为已解决问题将答案标记为已接受,请单击答案旁边的复选标记将其从灰色切换为已填写。
def count_many_times(n,lst):
''' func count how many combination we can make '''
if n==0:
return 1
if n<0:
return 0
counter=0
for num in lst:
''' this loop check wich number can bring me the n number by adding'''
counter += count_many_times(n-num,lst)
return counter
def string_to_int():
''' convert string to int '''
st_int = [int(x) for x in input().split(' ')]
return st_int
def main():
lst=[]
sub_lst = string_to_int()
while sub_lst[0] != 0: # this loop goes until we find 0
lst.append(sub_lst)
sub_lst = string_to_int()
for i in lst:
for j in i:
n=i[0] # take first number
num_parts=list(i[1:]) # take the other like alist to calulate combination
x = count_many_times(n,num_parts) # function give me num of combination
print(x)
main()
[1, 1, 1, 1]
[1, 1, 2]
[1, 2, 1]
[2, 1, 1]
[2, 2]
5