考虑python中的以下代码:
def main():
n = input( )
s = input( )
coins = [ 0 ]*n
dp = [ 0 ]*( s+1 )
print coins
print dp
for i in range( n ) :
coins[ i ] = input( )
dp[ 0 ]=0
dp[ 1 ]=1
for i in range( 2, s+1 ) :
min_val = 999999
for j in range( 0, n ) :
if i-coins[ j ] > 0 :
if dp[ i-coins[ j ] ] + 1 < min_val :
min_val = dp[ i-coins[ j ] ] + 1
print coins
print dp
print coins[ s ]
if __name__ == "__main__" :
main()
当我编译并运行这个程序时,我得到以下运行时错误:
File "test.py", line 33, in <module>
main();
File "test.py", line 30 in main
if dp[ i-coins[ j ] ] + 1 < min_val :
IndexError: list index out of range
它出什么问题了?
输入:
5 10
1 3 5 7 9