Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6593107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:38:23+00:00 2026-05-25T17:38:23+00:00

I have solved the following algorithm shown below. public static long park(int n) {

  • 0

I have solved the following algorithm shown below.

public static long park(int n)
{
   // precondition:  n >= 1
   // postcondition: Return the number of ways to park 3 vehicles,
   //   designated 1, 2 and 3 in n parking spaces, without leaving
   //   any spaces empty. 1 takes one parking space, 2 takes two spaces,
   //   3 takes three spaces. Each vehicle type cannot be distinguished
   //   from others of the same type, ie for n=2, 11 counts only once.
   //   Arrangements are different if their sequences of vehicle types,
   //   listed left to right, are different.
   //   For n=1:  1 is the only valid arrangement, and returns 1
   //   For n=2:  11, 2                     are arrangements and returns 2
   //   For n=3:  111, 12, 21, 3            are arrangements and returns 4
   //   For n=4:  1111,112,121,211,22,13,31 are arrangements and returns 7


    if(n==1)
        { return 1; }
    else if(n==2)
        { return 2; }
    else if(n==3)
        { return 4; }
    else
        {
        return (park(n-1) + park(n-2) + park(n-3));
        }
}

What I need help on is figuring out a followup problem which is to include empty parking spaces in the permutation. This should be solved recursively.

Let's designate a single empty space as E.
For n=1:  1,E                and returns 2
For n=2:  11,2,EE,1E,E1      and returns 5
For n=3:  111,12,21,3,EEE,EE1,E1E,1EE,11E,1E1,E11,2E,E2     and returns 13
For n=4:  there are 7 arrangements with no E, and 26 with an E, returns 33

I’ve spent many hours on this. I know how many arrangements there are without an empty space from the above algorithm. So I’ve been trying to figure out how many arrangements there are with 1 or more empty spaces. The union of these two sets should give me the answer.
For n, the number of single space permutations with one or more empty spaces is 2^n-1.
But I don’t think this will help me in a recursive solution.

Any guidance would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:38:24+00:00Added an answer on May 25, 2026 at 5:38 pm

    I think this works:

    public static long park(int n)
    {
        if(n==1)
            { return 2; }
        else if(n==2)
            { return 5; }
        else if(n==3)
            { return 13; }
        else
            {
            return (park(n-1) + park(n-1) + park(n-2) + park(n-3));
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: I have solved this by myself. See my answer below I have set
I've reduced my problem (table layout algorithm) to the following problem: Imagine I have
I need to solve the following problem. //pseudo algorithm you have four elements: elm1,
I have the following problem: I have a given number of identically formed items
I have the following struct: struct cell { int nmbr; struct cell *p; };
In some library I create I have to use following cast: public void Foo(IList<uint>
i'm not sure how to solve the following problem: i have a triangle with
I have the following problem that the standard library doesn't solve well, and I'm
I have solved this problem, I just need to know what to do. I
NOTE: I have solved the majority of this problem but have run into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.