Jump to content

Count the coins: Difference between revisions

m
Line 1,202:
len cache[] 100000 * 7 + 6
val[] = [ 1 5 10 25 50 100 ]
procfunc count sum kind . r .
if sum = 0
r =return 1
break 1
.
if sum < 0 or kind = 0
r =return 0
break 1
.
chind = sum * 7 + kind
if cache[chind] > 0
r =return cache[chind]
break 1
.
r2 = count (sum - val[kind]) kind r2
r1 = count sum (kind - 1 r1)
r = r1 + r2
cache[chind] = r
return r
.
print count 100 4 r
print rcount 10000 6
print count 10000100000 6 r
print r
count 100000 6 r
# this is not exact, since numbers
# are doubles and r > 2^53
print r
</syntaxhighlight>
 
2,053

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.