CSCE 235
Homework
Assignment 7 (Programming)
Assigned: March 5, 2008
Due: 12:30 p.m. March 14,
2008
(Homework 5
minutes late will not be accepted)
Principle of Inclusion-Exclusion
1. (15
points) How many elements are in
if there are 14
elements in
, 7 elements in
, and
(a) (2 points)![]()
(b) (3 points)![]()
(c)
(5 points) ![]()
(d)
(5 points) ![]()
2. (10 points) Of 500 contestants for an talent show on TV:
· 116 cannot sing,
· 125 cannot dance, and
· 302 cannot play a musical instrument
A contestant qualifies for the Finals if and only if the contestant (a) can sing, (2) can dance, and (3) play a musical instrument. If there are:
· 15 contestants who cannot sing and cannot dance,
· 22 contestants who cannot sing and cannot play a musical instrument,
· 17 contestants who cannot play a musical instrument and cannot dance
· 7 contestants who cannot sing, cannot dance, and cannot play a musical instrument.
How many contestants qualify for the Finals?
3. (20 points) An Electronics store (that sells only TVs, DVD players, and Stereos) releases a report of its 100 customers who bought electronics in March 2003. Every customer bought at least one type of electronics.
· 44 customers bought a TV
· 50 customers bought a DVD player
· 35 customers bought a Stereo
· 20 customers bought a Stereo and a DVD player
· 6 customers bought a TV and a DVD player
· 6 customers bought a TV, a Stereo and a DVD player
Determine the numbers of customers who bought
(a) a TV and a Stereo
(b) a TV and a Stereo, but not a DVD player
(c) only one electronic item
(d) more than one electronic item
The Addition and Multiplication Rules
4. (5 points) You are the manager of a talk show and you are in charge of selecting Oscar-nominated actors/actresses to appear on the show.
You are given the following list of actors: George Clooney, Daniel Day-Lewis, Johnny Depp, Tommy Lee Jones, and Viggo Mortensen
You are given the following list of actresses: Cate Blanchett, Julie Christie, Marion Cotillard, Laura Linney, and Ellen Page
(a) (3 points) In how many ways can an actor and an actress be selected to appear on the show?
(b) (2 points) In how many ways can an actor or an actress be selected to appear on the show?
5. (10 points) Using only the alphabet letters A, B, C, D, and E,
(a) How many two-letter combinations can be formed?
(b) How many three-letter combinations can be formed?
(c) How many four-letter combinations can be formed?
(d) How many two- or three- or four-letter combinations can be formed?
(e) How many four-letter combinations can be formed if the second letter must be either D or E?
6. (20 points) A standard deck of 52 playing cards has four suits (spades, hearts, clubs, and diamonds). Each suit has 13 cards, from 2 to 10 and J, Q, K, and Ace. In how many ways can one draw from a standard deck of 52 playing cards:
(a) (3 points) A club or a diamond or a heart?
(b) (3 points) A king (K) or a queen (Q) or a jack (J)?
(c) (3 points) A card numbered 6 through 10?
(d) (3 points) A card numbered 6 through 10 or a king?
(e) (5 points) Two cards of different suits?
(f) (8 points) Two cards: the first card an ace or a king; and then without replacing the first card back into the deck, the second card an ace or a king again?
The Pigeon-Hole Principle
7. (15 points)
Forty buses are to be used to transport 2500 fans from
(a) Prove that one of the buses will carry at least 63 passengers.
(b) Prove that one of the buses will have at least 18 empty seats.
8. (10 points)
You are a magician. You tell the
audience that there are at least four people
in the audience who were born in the same state (out of 50 states in the
Programming
9. (50 points)
Toolbox/Application. An online
bookstore is building an accounting program to keep track of the possible
choices that customers have in purchasing books from the bookstore. Suppose there are K book categories. For
each book category k, there are
different books. Now, the store wants to figure out, given
that if a customer wants to buy
books of category k,
how many choices are there for the customer.
So, if a customer wants to buy 3 books of category 1, 4 books of
category 2, and so on, the store wants to figure out automatically how many
combinations there are. Assume that each
time, a customer can buy more than one copy of the same book.
Your task is to build this system. Basically, you need to implement the addition (sum) and multiplication (product) rules. The system will read in a file like this. (In the following, comments are added to explain what each value means and will not appear in the actual input file.)
4
// this indicates the number of categories in the bookstore
1 10 2 8 3 10 4
10 // 10 books of category 1, 8 books
of category 2, …
1 2 2 3 3 0 4 0 //
customer wants to buy 2 books of category 1, 3
// books of category 2, none of category 3, none // category 4
1 0 2 0 3 0 4 1 //
customer wants to buy 1 book of category 4
999 1 2 3 //
customer wants to buy 3 books out of category 1 // or category 2
999 4 1 3 2 //
customer wants to buy 2 books of category 4, or // category 1, or category 3
END
The first line has only one number to indicate the number of book categories in the bookstore. The second line is the list of books under each category. Then, we have four lines of customers. The first customer is very specific. He or she wants to buy 5 books, two of category 1, and three of category 3. However, the third customer is not as specific. The ‘999’ label indicates that the third customer wants to buy 3 books out of category 1 or category 2. As long as the three books are of either category 1 or category 2, then that is fine with him/her. The input file ends with an “END”.
The output of your bookstore accounting program should have the following:
Number of choices
for customer 1: 51200
Number of choices
for customer 2: 10
Number of choices
for customer 3: 5832
Number of choices
for customer 4: 900
Important:
(a) Your program should be
generalized to accept any random K. Our test set will use at least a small K and
a big K to check the correctness of your program.
(b) Make sure that you have a
README file to describe how to compile and run your program.
Problems
based on (Rosen 2003, Goodaire and Parmenter 2002).