-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path31.py
68 lines (61 loc) · 1.63 KB
/
31.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import time
t1 = time.clock()
val = [200,100,50,20,10,5,2,1]
target = 200
def getUb (val):
return target//val + 1
ways = 0
#2pound
for a in range (0, getUb(val[0])):
if (a*val[0] >target):
break
#1pound
for b in range (0,getUb(val[1])):
if (a*val[0] + b*val[1] >target):
break
#50cent
for c in range (0, getUb(val[2])):
if (a*val[0] + b*val[1] + c*val[2] >target):
break
#20cent
for d in range (0, getUb(val[3])):
if (a*val[0] + b*val[1] + c*val[2] + d*val[3] >target):
break
#10cent
for e in range(0, getUb(val[4])):
if (a*val[0] + b*val[1] + c*val[2] + d*val[3] + e*val[4]>target):
break
#5cent
for f in range(0, getUb(val[5])):
if (a*val[0] + b*val[1] + c*val[2] + d*val[3] + e*val[4] + f*val[5] >target):
break
#2cent
for g in range(0, getUb(val[6])):
if (a*val[0] + b*val[1] + c*val[2] + d*val[3] + e*val[4] + f*val[5] + g*val[6] >target):
break
#1dent
for h in range(0,getUb(val[7])):
if (a*val[0] + b*val[1] + c*val[2] + d*val[3] + e*val[4] + f*val[5] + g*val[6] + h*val[7] >target):
break
else:
if((a*val[0] + b*val[1] + c*val[2] + d*val[3] + e*val[4] + f*val[5] + g*val[6] + h*val[7]) == target):
ways +=1
print('Execution time: ', time.clock() - t1)
print(ways)
'''
import time
t1 = time.clock()
val = [200,100,50,20,10,5,2,1]
ub = 7
target = 200
def ways (target, ub, val):
if (ub == 0):
return 1
result = 0
while (target >= 0):
result += ways(target, ub-1,val)
target -= val[ub-1]
return result
print(ways(target,ub,val))
print('Execution time: ', time.clock() - t1)
'''