-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin.py
36 lines (29 loc) · 807 Bytes
/
coin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# All Ways count
# def coun(arr, m, n):
# if n == 0:
# return 1
# if n < 0:
# return 0
# if m <= 0 and n >= 1:
# return 0
# return coun(arr, m-1, n) + coun(arr, m, n-arr[m-1])
# min Way
def count(S, m, n):
table = [[0 for x in range(m)] for x in range(n+1)]
for i in range(m):
table[0][i] = 1
for i in range(1, n+1):
for j in range(m):
x = table[i - S[j]][j] if i-S[j] >= 0 else 0
y = table[i][j-1] if j >= 1 else 0
table[i][j] = x + y
return table[n][m-1]
def count(S, m, n):
table = [0 for k in range(n + 1)]
table[0] = 1
for i in range(0,m):
for j in range(S[i],n+1):
table[j] += table[j - S[i]]
print(i)
print(table)
return table[n]