前提・実現したいこと
このコードの再帰関数recursive(index,sum_value)
のところの処理の流れを理解したいです.
発生している問題・エラーメッセージ
特にエラーなどはありません.
該当のソースコード
python3
1N = 5 2table = [1, 5, 7, 10, 21] 3num_query = 4 4num = [2, 4, 17, 8] 5 6check = [False]*2001 7 8def recursive(index,sum_value): 9 10 if index == N: 11 check[sum_value] = True 12 return 13 14 recursive(index+1,sum_value) #非加算 15 16 if sum_value+table[index] <= 2000: 17 recursive(index+1,sum_value+table[index]) 18 19recursive(0,0) #ここの処理がどのように進んでいくかが分かりません
分からないこと
まずはじめにrecursive(0.0)
が始まると,index = 0, sum_value = 0
になってindex != 5
だからrecursive(1.0)
が始まって,同様にしてrecursive(5.0)
まで行ったら,index == 5
だからcheck[0] = True
になって関数を抜け出してしまい,recurisive
関数内の
if sum_value+table[index] <= 2000: recursive(index+1,sum_value+table[index])
ここの処理がいつ行われるのかが分かりません.
補足情報
AOJ ALDS1_5_A Exhaustive Search のある解答コードの一部です.
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。