Skip to content

Commit aaf40d9

Browse files
committed
Finally starting to understand dynamic programming
1 parent b6d3df5 commit aaf40d9

File tree

1 file changed

+21
-0
lines changed
  • Dynamic Programming/The Coin Change Problem

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#@Author Andrew Kuznetsov
2+
#@Note Format given by https://code.google.com/p/soc/wiki/PythonStyleGuide.
3+
#@Note Not an optimal solution given access/write runtimes of python lists (as opposed to arrays).
4+
5+
def calculateAmountGivenCoinList(coin_list, amount):
6+
num_coin_list_length = (amount+1)
7+
num_coin_list = [0] * (num_coin_list_length)
8+
num_coin_list[0] = 1
9+
for coin in coin_list:
10+
for current_index in xrange(coin, (num_coin_list_length)):
11+
num_coin_list[current_index] += num_coin_list[current_index - coin]
12+
return num_coin_list[amount]
13+
14+
def main():
15+
amount = int(raw_input().split()[0])
16+
coin_list = raw_input().split()
17+
coin_list = [int(i) for i in coin_list]
18+
print calculateAmountGivenCoinList(coin_list, amount)
19+
20+
main()
21+

0 commit comments

Comments
 (0)