Suppose you have an unlimited number of stamps, with denominations of 6, 7, and 8, what is your biggest non-paying postage?
Small series of fingers and toes forget, the answer is: 1.7 yuan
So that's the problem? Why is 1.7, so small make up with Python solve this elementary math problem.
I. Permutations and combinations
Suppose 6, 7, and 8 have 50 sheets (50 sheets enough) to calculate all possible combinations first
Second, sort, go heavy
Sort the rows first, order from small to large, queue up, and use the sort () function here (if you sort by bubbles, you're out!) )
The sort function simply sorts the list sequence and does not return a value
After the sort is done, the next step is to remove the duplicated data
Third, take out the numbers that cannot be generated
The number that is not in the combination above is the number that cannot be generated, so we can take it out first.
The extracted data is placed in the R queue.
Taking the last data from the R queue is the answer.
Iv. Reference Code
# Coding:utf-8
A = 6
b = 7
c = 8
t = number of 50 # Tickets
s = [] # permutation combination all put here
# generated combinations
For I in Range (t+1):
S1 = A*i
S.append (S1)
For j in Range (t+1):
S2 = a*i+b*j
S.append (S2)
for k in range (t+1):
S3 = a*i + b*j + c*k
S.append (S3)
# sort
S.sort ()
# Remove Duplicates
News = []
For I in S:
If I not in news:
News.append (i)
Print ("The maximum number of combinations generated%s"%news[-1])
# extract numbers that are not in the list list
r = []
For I in Range (6*t):
If I in news:
Pass
Else
R.append (i)
Print ("Combination cannot generate number%s"%r)
Print ("The maximum number that cannot be generated is%s"%r[-1])?
Python Note 1-solving math problems for pupils in Python