这是错误:
Message File Name Line Position Traceback 34 count 25 TypeError: unsupported operand type(s) for -: 'int' and 'str'
代码可在此处找到:
import sys N = int(sys.stdin.readline()) #4 munten = [] #1, 2, 5, 10 for p in range(0, N): munten.append(sys.stdin.readline()) bedrag = int(sys.stdin.readline()) #13 m = len(munten) def count(S, m, bedrag): table = [[0 for x in range(m)] for x in range(bedrag+1)] for i in range(m): table[0][i] = 1 for i in range(1, bedrag+1): for j in range(m): x = table[i - S[j]][j] if i-S[j] >= 0 else 0 y = table[i][j-1] if j >= 1 else 0 table[i][j] = x + y return table[bedrag][m-1] print(count(munten, m, bedrag)) #output = 16
输入:N = 4(数组中的硬币数量),(数组)munten =(1、2、5、10),(支付金额)bedrag = 13->(我可以组合的数量用数组中的硬币支付)输出= 16
答案 0 :(得分:1)
munten
是代码中的字符串列表。
for p in range(0, N):
munten.append(int(sys.stdin.readline()))
执行示例
> python3 sample.py
> 4 #N
> 1 #munten0
> 2 #munten1
> 5 #munten2
> 10 #munten3
> 13 #bedrag
16