Skip to content

Instantly share code, notes, and snippets.

@Irene-123
Created May 25, 2020 03:14
Show Gist options
  • Save Irene-123/9a88aedbccca72868ef0a417a9648ba1 to your computer and use it in GitHub Desktop.
Save Irene-123/9a88aedbccca72868ef0a417a9648ba1 to your computer and use it in GitHub Desktop.
The coin change problem
```python
import math
import os
import random
import re
import sys
#
# Complete the 'getWays' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. LONG_INTEGER_ARRAY c
#
n,m = list(map(int,input().strip().split(' ')))
coins = list(map(int,input().strip().split(' ')))
def count_make_change_recursive(n,coins,m):
if n<0:
return 0
if n==0:
return 1
if m==0:
return 0
return count_make_change(n-coins[m-1], coins, m) + count_make_change(n,coins,m-1)
def count_make_change(n,coins,m):
count=[0]*(n+1)
count[0]=1
for i in range (0,m):
sum=0
for j in range(coins[i],n+1):
count[j]+=count[j-coins[i]]
return count[n]
print(count_make_change(n,coins,m))
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment