Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Suppose there is a group of n people to be seated at a two tables, the first with r chairs and the second with n
Suppose there is a group of n people to be seated at a two tables, the first with r chairs and the second with n rchairs. We do not care who sits in which chair, just who sits at which table. The problem is to compute the number of different ways the people could be assigned to tables. One way of assigning them is to make them all stand in a line, and then assign the first r people in the line to the first table, and the remaining n-r people to the second one. The number of ways of ordering the people into a line is n! n (n-1) (n-2) 3 2' 1, because there are n possible choices for the first in line and for each of these, n 1 choices for the second person in line, and so forth. But of these orderings, any way of rearranging the first r people in line (of which there are r! ways) results in the same table assignment, and similarly, each of the s ways of rearranging the remaining s n r people left in line after the first r people have been seated also results in the same table assignment. So by dividing by the two factors r! and s! to account for these repetitions of the same table assignment, we get n! /(r!'s!) total different table assignments. Submit a program that starts with a function definition for factorial(n), which returns the number n! Then the main program should call that function three total number n of people, "Enter the number of chairs at table 1"to get the number r, and "Enter the number of chairs at table 2" to get s. Assume for now that r s n. It should then print the total number of different table assignments, preceded by the words "The number of table assignments is" This printed number should be in integer without a decimal point. This time the grading is not sensitive to white space, so extra spaces and new lines are OK (but not colons). So for the first test case, the interaction should look like Enter the number of people Enter the number of chairs at table 1 Enter the number of chairs at table 2 The number of table assignments is 20 Next, enhance the program for more than two tables. Keep prompting for the number of chairs at tables until the number equals n. lf the numbers of chairs at the tables are r, s x, the reasoning above shows that the number of different assignments is nl/ (r! x!). So and example s! t interaction would be Enter the number of people Enter the number of chairs at table 1 Enter the number of chairs at table 2 Enter the number of chairs at table 3 The number of table assignments is 90
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started