Download HW1 Solution - UCSD VLSI CAD Lab

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Addition wikipedia , lookup

Elementary mathematics wikipedia , lookup

Location arithmetic wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Arithmetic wikipedia , lookup

Approximations of π wikipedia , lookup

Positional notation wikipedia , lookup

Elementary arithmetic wikipedia , lookup

Transcript
Yuncong Chen
Assignment HW1 due 04/07/2014 at 12:59pm PDT
CSE21 Spring2014
• [5]*[4]
• [5]ˆ2*[4]
• ([5]+C([5],2))*[4]
1. (1 pt)
Standard automobile license plates in Pennsylvania have 1
nonzero digit, followed by 3 letters, followed by 4 digits. How
many different standard plates are possible in this system?
3. (4 pts)
There are 9 chairs in a row. 5 boys and 4 girls are to be seated
in the chairs. In how many ways can this be done
SOLUTION:
(a) if there are no restrictions?
There are only 9 possibilities for the first number since a 0 is not
allowed. Then, there are 26 possibilities for each letter, and 10
choices for the rest of the numbers. Thus, the total number of
different standard plates is 9 · 263 · 104
(b) if boys and girls must alternate?
(c) if all the boys must sit next to each other (i.e., in consecutive
chairs)?
Correct Answers:
• 9*26ˆ3*10ˆ4
(d) if all the boys must sit next to each other, and all the girls
must sit next to each other?
2. (3 pts)
A vendor sells ice cream from a cart on a sidewalk in Mission
Bay. He offers 5 different flavors and 4 different kinds of cones.
SOLUTION:
(a) How many different single-scoop ice cream cones can you
buy from this vendor?
(a) Since there are no restrictions, there are 5 boys + 4 girls = 9
distinct guests, so there are 9! ways to arrange them.
(b) How many different two-scoop ice cream cones can you buy
from this vendor? Assuming chocolate on top of strawberry is
different than strawberry on top of chocolate?
(b) Since girls and boys must alternate, there is only one possible template: BGB..BGB. Then there are 4! ways to arrange the
girls, and 5! ways to arrange the boys. This gives 4! · 5! ways.
(c) What would be the answer to (b) if, e.g., chocolatestrawberry is considered the same as strawberry-chocolate?
(c) If the boys must be next to each other, we can treat them as a
block. There are 5 ways to place this block relative to the girls.
Then there are 4! ways to arrange the girls, 5! ways to arrange
the boys within the block, the answer is 5 · 4! · 5! ways.
SOLUTION:
(d) Like in part (c), we can treat the boys as a block and the girls
as a block as well. There are only two ways to place the two
blocks. Then again 4! ways to arrange the girls, and 5! ways to
arrange the boys. Thus, there are 2 · 5! · 4! ways to arrange all.
(a) Here we use the Rule of Product. Since there are 5 ways
to choose a flavor and 4 ways to choose a cone, there are 5 · 4
different single-scoop ice-cream cones.
Correct Answers:
•
•
•
•
(b) Now there are 52 ways to choose two flavors and 4 ways to
choose a cone, so there are 52 · 4 different two-scoop ice-cream
cones.
(c) For flavors, we consider two cases. One case is that both
scoops are of the same flavor; there are 5 choices. The other
case is if the two scoops are different; there are C(5, 2) choices.
Together there are 5+4 choices for flavors. Then combine with
the choices of cone, we get there are (5 + C(5, 2)) · 4 different
two-scoop ice-cream cones.
[9]!
[5]!*[4]!
[4+1]*[4]!*[5]!
[5]!*[4]!*2
4. (4 pts)
An n-digit decimal number is a list of n digits where each digit
is one of {0,1,2...9} and the first digit is nonzero.
(a) How many n-digit numbers are there (as a function of n)?
Correct Answers:
1
How many distinct anagrams can be created from the word
MILLENNIUM if the anagrams do not need to be meaningful?
(b) How many n-digit numbers contain no 1’s?
(c) How many n-digit numbers contain at least one 2?
(An anagram is a rearrangement of letters. For example, LEAPT
is an anagram of PLATE.)
(d) For n > 2, how many n-digit numbers contain at least one 2
and at least one 3, but no 7’s?
SOLUTION:
SOLUTION:
There are 10! permutations of this word, but we need to cancel
out the over-counting due to duplicate letters.
(a) The first digit can’t be a 0, but the remaining n-1 digits can
be any digit, so the answer is: 9 · 10n−1
The rule of thumb is: for each group of identical letters, divide the total permutation count by the number of permutations within that group. In MILLENNIUM, there are four such
groups: MM, II, LL, NN; and the number of permutations
10!
within each group is 2!. So the final answer is 2!·2!·2!·2!
(b) The first digit can’t be a 0 or 1, and none of the remaining
n-1 digits can be 1, so the answer is: 8 · 9n−1
(c) It’s easier to think about this in terms of how many numbers
don’t contain a 2. Then, subtract that from the total number of
possibilities.
Correct Answers:
• 10!/(2!*2!*2!*2!)
You can find how many n-digit numbers contain no 2’s using the
same method as in part (b), 8 · 9n−1 .
In part (a) we saw the total number of possibilities is 9 · 10n−1
(a) How many ways are there to form a list of three letters (with
repetition allowed) from the letters in the word MILLENNIUM,
if no letter can be used more often than it appears in MILLENNIUM?
So the final answer is 9 · 10n−1 − 8 · 9n−1
(b) What about lists with four letters?
(d) Excluding 7 leaves us with 8 choices for first digit, and 9
choices for the remaining digits. Without furthre constraints,
the total number of such numbers is 8 · 9n−1 .
SOLUTION:
6. (2 pts)
(a) Without any constraints, the number of all possible threeletter words is 63 . Now we need to remove:
The constraint is “at least one 2 AND at least one 3”. Often
when you see a condition like “at least one is X”, it is easier to
consider the complementary case, which is “there is no X”. Also
recall that the complement of “A AND B” is “not A OR not B”.
So the complement of our constraint is “there is no 2 OR there
is no 3”.
◦ those with three of the same letter: there are 6 such words
◦ those with two E’s: there are C(3, 2) · 5 such words
◦ those with two U’s: same as (2).
So the answer is 63 − 6 − 2 ·C(3, 2) · 5.
Then recall that the size of the union of two sets can be calculated as |X ∪Y | = |X| + |Y | − |X ∩Y |. So the size of our complement set is (# of numbers with no 2) + (# of numbers with no 3)
- (# of numbers with no 2 or 3) = 2 · 7 · 8n−1 − 6 · 7n−1 .
(b) Without any constraints, the number of all possible threeletter words is 64 . Now we need to remove:
◦ those with four of the same letter: there are 6 such words
◦ those with exactly three of the same letter: there are
P(6, 2) · 4 such words
◦ those with exactly two E’s or exactly two U’s. This is
equal to {# with exactly two E’s} + {# with exactly two
U’s} - {# with exactly two E’s AND exactly two U’s} =
2 ·C(4, 2) · 52 −C(4, 2)
Substracting this from the total number at the beginning gives
the final answer 8 · 9n−1 − (2 · 7 · 8n−1 − 6 · 7n−1 ) .
Correct Answers:
•
•
•
•
9*10ˆ(n-1)
8*9ˆ(n-1)
9*10ˆ(n-1)-8*9ˆ(n-1)
8*9ˆ(n-1)-(2*7*8ˆ(n-1) - 6*7ˆ(n-1))
So the answer is 64 − 6 − P(6, 2) · 4 − (2 ·C(4, 2) · 52 −C(4, 2))
Correct Answers:
• 6ˆ3 - 6*C(3,3) - 2*(C(3,2)*(6-1))
• 6ˆ4 - 6 - P(6,2) * 4 - (2 * C(4,2) * 5ˆ2 - C(4,2))
5. (2 pts)
2
Consider words which only use the letters A, B, C, D, E.
Each monotonically increasing sequence of n digits corresponds
to a way to separate n stars into 9 bins (using 8 bars). The number of stars that fall in the i’th bin is the repetition of digit i in
the sequence. So the answer is C(n+8, 8).
(a) How many four-letter words can be made using these letters?
Solution 1:
(b) How many four-letter words have exactly two vowels and
two consonants?
Suppose the length of the sequence is n. Construct a grid with 9
rows and n columns, and (1,1) is the lower left corner. We can
think of each monotonically increasing sequence as a path that
starts from (1,1) and reaches the rightmost column at the end.
7. (3 pts)
(c) Of the four-letter words with exactly two vowels and two
consonants, how many have distinct vowels?
We consider paths that end at (n, k), which are equivalent to
sequences whose last digit is k. The number of such paths is
exactly the number of ways to arrange n − 1 RIGHT moves and
k − 1 UP moves. This is C(n − k − 2, n − 1). Denote this number Lk , and it is the number of sequences that has length n and
whose last digit is k.
SOLUTION:
(a) 5 choices at each of the 4 positions: 54 .
(b) There are four cases:
◦ two vowels are different, two different consonants: C(3, 2)·
4!
◦ two vowels are different, two consonants are the same:
3 · 4!/2!
◦ two vowels are the same, two different consonants: 2 ·
C(3, 2) · 4!/2!
◦ two vowels are the same, two consonants are the same:
2 · 3 · 4!/(2! · 2!)
Since we are not restricting the last digit of the sequence, the
final answer should be the sum of Lk over k = 1, 2, · · · , 9. This
is ∑9k=1 C(n − k − 2, n − 1)
Solution 2:
We divide the space of all sequences of length n into subsets
according to the number of different digits (or the number of
segments) in the sequence. There are n subsets, corresponding
to sequences with 1 segment, that with 2 segments, that with 3
segments... and that with n segments.
Summing these up gives the answer.
(c) This is the first two cases in (b).
We count the size of a specific such subset that corresponds the
sequences with k segments.
Correct Answers:
• 5ˆ4
First, realize that there are C(9, k) choices as for what the digits
• C(3,2)*4!+2*3*4!/2!+C(3,2)*4!/2!+2 * 3 * 4!/(2!*2!)
are.
• C(3,2)*4!+C(3,2)*4!/2
Once the digits are selected, the problem becomes deciding how
long each segment is. This can be approached by the “bars and
stars” technique.
8. (3 pts)
Think about separating n stars into k bins using k −1 bars, where
a bin is allowed to have no stars. The number of such separations is exactly the number of ways to arrange k − 1 bars and n
stars. This is C(n + k − 1, k − 1) since we can simply pick the
locations of bars.
A monotone increasing number consists of digits taken from
the set {1, 2, . . . , 9}, with each digit greater than or equal
to its neighbor digit to the left (if that digit exists). E.g.,
1112256888899 is a monotone increasing number with 13 digits. How many 7-digit monotone increasing numbers are there?
Back to our problem, the number of stars in each bin directly
corresponds to the length of each segment. Note that we do
have an extra constraint that each “bin” should contain at least
one star because a segment cannot have zero length. To deal
with this, we can set aside k stars, and do the vanilla “bars and
stars” with n − k stars. Then for each separation we find, we
make sure no bins are empty by giving back a star to each bin.
(hint: use the staircase method or “stars and bars” method)
SOLUTION:
Solution 0:
3
Applying “bars and stars” with k − 1 bars and n − k stars gives
us C(n − 1, n − k) possibilities.
An icosahedron has 20 faces. Each face is an equilateral triangle. Five faces meet at each vertex. Determine the number of
vertices V and the number of edges E in an icosahedron. Write
the sum V + E for your answer.
Combining the steps above, we find that there are C(9, k) ·C(n −
1, n − k) mono. increasing sequences with k segments.
SOLUTION:
As a final step, we need to sum this count for all subsets where
k = 1, · · · , n. The answer is ∑nk=1 C(9, k) ·C(n − 1, n − k)
Imagine for each vertex we draw an outward arrow along each
edge that is connected with it. At the end, each edge will bear
exactly two arrows at opposite directions, which come from the
two end vertices of this edge respectively. Let us count the number of arrows. On the one hand, there are 5 arrows from each
vertex, that is 5 · V ; on the other hand, there are two arrows on
each edge, that is 2 · E. Theses two quantities must be equal.
This gives our first formula, 5 ·V = 2 · E.
Solution 3 (Dynamic programming) :
Denote L(n, j) as the number of m.i. sequences of length n that
ends with digit j.
The number of n-sequences that end with k is the sum of the
number of (n-1)-sequences that end with digits equal or smaller
j
than k. Thus, we can derive a recursion: L(n, j) = ∑i=1 L(n −
1, i), or equivalently, L(n, j) = L(n − 1, j) + L(n, j − 1).
With a similar reasoning, since each edge is shared by two faces,
and each face has three edges, we know 3 · F = 2 · E.
The base cases are L(1, i) = 1 for all i = 1, · · · , 9.
This gives E = 30. Apply this to the previous formula, we obtain V = 12.
Correct Answers:
• 6435
Correct Answers:
9. (3 pts)
• 42
c
Generated by WeBWorK,
http://webwork.maa.org, Mathematical Association of America
4