""" Насколько я понял, мы имеем некоторый массив весов, комбинируя которые, нужно получить целевой вес """ class LorryWeight: def __init__(self): self.count = 0 def combs(self, array, target, length): self.sub_sum(array, target, 0, length) def sub_sum(self, array, target, index, length): if target == 0: self.count += 1 return if target < 0: return for i in range(index, length): self.sub_sum(array, target-array[i], i, length) def printer(self): print(self.count) if __name__ == '__main__': weights = [int(x) for x in input().split()] target = int(input()) length = len(weights) lorry_weights = LorryWeight() lorry_weights.combs(weights, target, length) lorry_weights.printer()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question