You have in your wallet $300, which you want to spend completely. You decide to spend all of it by buying food from a fancy restaurant with the following menu:
tofu scramble: $1
pancakes: $5
brunch combo: $20
saffron infused peach tea: $50
truffles: $100
caviar: $200
Let O be the number of different ways that you can spend exactly $300. What are the last 3 digits of O ?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
@Thaddeus Abiy Is there another way of solving this problem, using combinactorics method or algebra.I am clue less.
Log in to reply
For CS problems,a programming solution is easier to understand. But surprisingly,for this problem there is a very mathematical solution! You can construct a generating function and read the coefficient next to x 3 0 0
Log in to reply
Oh and the function is ( ( 1 − x ) ( 1 − x 5 ) ( 1 − x 2 0 ) ( 1 − x 5 0 ) ( 1 − x 1 0 0 ) ( 1 − x 2 0 0 ) ) 1
Log in to reply
@Thaddeus Abiy – Thanks this is helpful
Log in to reply
@Mardokay Mosazghi – A bit late but,Happy Birthday!
@Thaddeus Abiy – In advance is this called Ordinary generating functions
Thaddeus, I don't understand how your program works. Can you explain?
Small BASIC
sum = 0
For a = 0 To 300
For b = 0 To 60
For c = 0 To 15
For d = 0 To 6
For e = 0 To 3
For f = 0 To 1
total = a + 5*b + 20*c + 50*d + 100*e + 200*f
If total = 300 Then
sum = sum + 1
EndIf
EndFor
EndFor
EndFor
EndFor
EndFor
EndFor
TextWindow.Write(sum)
...
f = 1/((1-x)(1-x^5)(1-x^20)(1-x^50)(1-x^100)(1-x^200))
That is the generating function
Here is what you do to get the coefficient of x^300:
Coefficient[Series[f,{x,0,35}],x,300]
It gives 1935
:)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
conta=935
count = 0
for(i in seq(0,300,1)) for(j in seq(0,300,5)) for(k in seq(0,300,20))
for(a in seq(0,300,50)) for(b in seq(0,300,100)) for(c in seq(0,300,200))
if(i+j+k+a+b+c==300) count = count +1
count
In Python:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
I used a simple Python program to solve the problem. See below:
x=0
for i in range(2):
for j in range(4):
for k in range(7): for l in range(16): for m in range(61): for n in range(301): s=200*i+100*j+50*k+20*l+5*m+n if s==300: x+=1 print x,i,j,k,l,m,n
( x )2*8 + n = 25. so, we have 934 + 5 = 935.
Problem Loading...
Note Loading...
Set Loading...
Behold the power of Dynamic Programming!