Question

We have n parking spaces, where the car can park within 1 parking space, but the...

We have n parking spaces, where the car can park within 1 parking space, but the truck needs to park within 2 parking space. Implement the solution(n) function that will return a set of string that corresponds to a full parking lot configuration for n spaces.

Example: solution(6), where 6 is the number of space we have, -> one possible solution from the set could be CTTC (1 + 2 + 2 + 1 = 6).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C++ program

#include <iostream>
#define ARR_SIZE 100
using namespace std;

void solution(int n, int i)
{ static char arr[ARR_SIZE];
if (n == 0)
{
for(int k=0;k<i;k++)cout<<arr[k];
cout<<"\n";
}
else if(n > 0)
{   
for (int k = 1; k <= 2; k++)
{
if(k==1)arr[i]= 'C';
if(k==2)arr[i]= 'T';
solution(n-k, i+1);
}
}
}
int main()
{
int n = 6;
cout<<"parking lot configuration for "<<n <<" spaces \n";
solution(n, 0);
return 0;
}

//sample output

Add a comment
Know the answer?
Add Answer to:
We have n parking spaces, where the car can park within 1 parking space, but the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need...

    Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example in the PPT) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked beyond their time...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • Problem List Previous Problem Next Problem (4 points) When parking a car in a downtown parking...

    Problem List Previous Problem Next Problem (4 points) When parking a car in a downtown parking lot, drivers pay according to the number of hours or fraction thereof. The probability distribution of the number of hours cars are parked has been estimated as follows: x 12 3456 78 P(X) 0.224 0.128 0.102 0.088 0.064 0.03 0.020.344 A. Mean B. Standard Deviation = The cost of parking is 4.25 dollars per hour. Calculate the mean and standard deviation of the amount...

  • Main objective: Solve the n queens problems. You have to place n queens on an n...

    Main objective: Solve the n queens problems. You have to place n queens on an n × n chessboard such that no two attack each other. Important: the chessboard should be indexed starting from 1, in standard (x, y) coordinates. Thus, (4, 3) refers to the square in the 4th column and 3rd row. We have a slight twist in this assignment. We will take as input the position of one queen, and have to generate a solution with a...

  • I Do We Have the Complete Solution Set? A differential operator in R[D] has order n can be writte...

    I Do We Have the Complete Solution Set? A differential operator in R[D] has order n can be written out in the form o(n-1) with the last coefficient cn (at least) not equal to zero. The key to determining the dimension of these solution spaces is the following existence and uniqueness theorem for initial value problems. 'So it can be efficiently described by giving a basis. ethciently described by giving a basis Theorem 1 (Existence and Unique ness Theorem for...

  • For this assignment, suppose that a fence is recording entry and exit into the park via...

    For this assignment, suppose that a fence is recording entry and exit into the park via a string as the gate swings open and folks walk in or out with their pet. For example, C++ DP+dp+CP+cp would indicate that an adult dog and an adult entered the park, then a puppy and child entered the park, then an adult cat and an adult entered the park and finally a kitten and a child entered the park. From this information, note...

  • We have root n machines, each having 10 root n memory space. The input is a...

    We have root n machines, each having 10 root n memory space. The input is a set of items (i; vi), for i = 1; 2; : : : ; n, distributed in an arbitrary order among the root n machines. We want to compute the output (i; P ji vj ), for i = 1; : : : ; n. The n output pairs can also be distributed in an arbitrary order on the root n machines. Please design...

  • [10 marks] Assume that we have two decimal positive numbers A and B. Both numbers have n digits. ...

    [10 marks] Assume that we have two decimal positive numbers A and B. Both numbers have n digits. We want to know what is the minimum number of swaps that we need in order to get from number A to B, where in each swap we choose two digits of a number and simply swap them For simplicity, we assume that A and B do not have the digit 0 in them, and that A and B have the set...

  • TSD.1 In this problem, we will see (in outline) how we can calculate the multiplicity of a monatomic ideal gas This derivation involves concepts presented in chapter 17 Note that the task is to...

    TSD.1 In this problem, we will see (in outline) how we can calculate the multiplicity of a monatomic ideal gas This derivation involves concepts presented in chapter 17 Note that the task is to count the number of microstates that are compatible with a given gas macrostate, which we describe by specifying the gas's total energy u (within a tiny range of width dlu), the gas's volume V and the num- ber of molecules N in the gas. We will...

  • Problem 2 We have seen that, if a matrix A is invertible, then we can express...

    Problem 2 We have seen that, if a matrix A is invertible, then we can express the unique solution of Az = b as I = A-15. Soon, we will introduce ideas that help us understand At = b better when A is not invertible. This problem is preparation for that! 11 301 1-3 -9 2 Let A = 2 6 0 1-2 -6 -5 (a) Solve the system A7 = 5. (b) What does the solution set of Az...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT