
David W. answered 01/23/16
Tutor
4.7
(90)
Experienced Prof
For any Word (Story) question, read and re-read it until you understand it and can put it into your own words. This problem statements includes a constraint: "exactly one 12-person tent is used." That means the problem really is, "How many combinations of fully-occupied tents (of 2, 3, 5, or 6 people) are needed for 16 people?"
Now, remember the decimal positional number system:
The number: abc is
a b c
0-9 0-9 0-9
There are 10*10*10=1000 possibilities ranging from 000 to 999.
So, let's create a "tent" number system:
Holds 6 Holds 5 Holds 3 Holds 2
No. of tents: 0-2 0-3 0-5 0-8 (total people must be 16)
It's easier to understand counting down:
Combination # 2-0 3-0 5-0 8-0
------- ------ ----- ----- ----
1 2 0 0 2
2 1 2 0 0
3 1 1 1 1
4 1 0 2 2
5 1 0 0 5
6 0 2 2 0
7 0 2 0 3
8 0 1 3 1
9 0 1 1 4
10 0 0 4 2
11 0 0 2 5
12 0 0 0 8
2 1 2 0 0
3 1 1 1 1
4 1 0 2 2
5 1 0 0 5
6 0 2 2 0
7 0 2 0 3
8 0 1 3 1
9 0 1 1 4
10 0 0 4 2
11 0 0 2 5
12 0 0 0 8
There are 12 combinations that can house 16 people.
Note: This is called "exhaustive enumeration" because we considered every possibility.
FOR A GOES FROM 2 TO 0 BY -1
FOR B GOES FROM 3 TO 0 BY -1
FOR C GOES FROM 5 to 0 by -1
FOR D GOES FROM 8 TO 0 BY -1
IF (A*6+B*5+C*3+D*2 = 16) THEN OUTPUT A,B,C,D
NEXT D
NEXT C
NEXT B
FOR B GOES FROM 3 TO 0 BY -1
FOR C GOES FROM 5 to 0 by -1
FOR D GOES FROM 8 TO 0 BY -1
IF (A*6+B*5+C*3+D*2 = 16) THEN OUTPUT A,B,C,D
NEXT D
NEXT C
NEXT B