Skip to content

Instantly share code, notes, and snippets.

@ajaykgp
Created July 6, 2013 10:21
Show Gist options
  • Save ajaykgp/5939494 to your computer and use it in GitHub Desktop.
Save ajaykgp/5939494 to your computer and use it in GitHub Desktop.
def countw(listd, total):
arr = [[None for x in range(total + 1)] for y in range(len(listd))]
for i in range(total + 1):
arr[0][i] = 1
for i in range(len(listd)):
arr[i][0] = 1
for i in range(1, len(listd)):
for j in range(1, total + 1):
arr[i][j] = arr[i - 1][j] + \
(0 if j - listd[i] < 0 else arr[i][j - listd[i]])
return arr[len(listd) - 1][total]
print countw([1, 2, 5, 10], 50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment