Question: Computer Science I Program 3 : Where to Sit? ( Recursion ) Please Check Webcourses for the Due Date Please read the whole assignment before
Computer Science I Program : Where to Sit? Recursion
Please Check Webcourses for the Due Date
Please read the whole assignment before you start coding
Objective
Give practice with recursion.
Give practice with functions in
Give practice with creating a design for a program without a given list of functions or structs.
Background Story
You and your friends are planning to get together to attend a movie! However, there are a few restrictions on where everyone can sit:
Some people don't want to sit next to each other.
Everyone should have access to popcorn! This means that for each person, either they bought popcorn, or the person directly to their left or the person directly to their right did.
For example, imagine that there are five people who want to attend the movie: Alia, Belinda, Carlos, Danica and Edward, where only Alia and Edward buy popcorn. In addition, Alia and Carlos can't sit next to each other and Belinda and Edward can't sit next to each other. Given these restrictions, they can sit in a single row in possible orders.
tableAliaBelinda,Carlos,Edward,DanicaAliaBelinda,Danica,Edward,CarlosBelindaAlia,Danica,Carlos,EdwardBelindaAlia,Danica,Edward,CarlosCarlosEdward,Danica,Alia,BelindaCarlosEdward,Danica,Belinda,AliaDanicaAlia,Belinda,Carlos,EdwardDanicaEdward,Carlos,Belinda,AliaEdwardCarlos,Belinda,Alia,DanicaEdwardCarlos,Danica,Alia,Belinda
Problem
Write two related programs where, given the list of people who are going to the movies together, the pairs of people who can't sit next to each other, and the list of people who are buying popcorn, determines the two following things:
Program the number of different orderings permutations of the movie attendees that satisfy all the restrictions.
Program the first ordering in lexicographical order of the movie attendees that satisfy all the restrictions.
Input
The first line of input contains two positive integers: the number of people attending the movie, and the number of pairs of people who do not want to sit next to each other.
The next lines will contain the information about each of the people attending the movie, with one person described per line. These lines will describe the people in alphabetical order. Each of these lines will have the following format:
NAME
Each name will be an uppercase alphabetic string with no more than characters. If the number is on the line, this indicates that that person does not have popcorn. If the number is on the line, this indicates that that person does have popcorn.
The following lines will each contain a pair of names, indicating two people who do not want to sit next to each other. It is guaranteed that each of the names appearing in this section will be one of the names listed previously as the movie attendees. Secondly, it's guaranteed that the two names on a single line will be distinct.
Output for Program
On a single line, simply output the total number of valid orderings of the people attending the movie sitting together in a single row, from left to right. It is guaranteed that the input data will be such that this value will be a positive integer.
Output for Program
Output, with one name per line, the first lexicographical valid ordering of the people attending the moving sitting together in a single row, from left to right. In lexicographical ordering, all lists starting with name will come before all lists starting with name if name comes before name alphabetically. Specifically, given two lists, to determine which one comes first lexicographically, find the first corresponding name on both lists that don't match. Which ever name comes first alphabetically, is the list that comes first in lexicographical order. Hint: since the given names are already in alphabetical order, the permutation algorithm shown in class will naturally evaluate the permutations in lexicographical order. Thus, to solve this program, the first valid solution found while running the algorithm will be the correct answer.
tableSample Input,Sample Output Sample Output ALIAALIA BELINDA,,BELINDA CARLOSCARLOS EDWARDDANICA DANICAEDWARD ALIA CARLOS,,BELINDA EDWARD,,ALEXALEX ELLIEELLIE FRANKLYNFRANKLYN JAMELLEJAMELLE MARTYMARTY SRIPRI WESSAMANTHA WES ALEX WES,,ELLIE MARTY,,ELLIE WES,,MEGANJACQUELINEANEESHA ARTHURARTHUR MATTHEWJACQUELINE MATTHEW MEGAN ROBINSON ROBIN
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
