File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Dynamic Programming/The Coin Change Problem Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments