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 7757103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:59:45+00:00 2026-06-01T12:59:45+00:00

for example if we consider the case for 3 places with numbers from [1..3]..we

  • 0

for example if we consider the case for 3 places with numbers from [1..3]..we can do it in 5 ways:

1 1 1
1 1 2
1 2 1
1 2 2 
1 2 3

In second place we cant have 3 as the difference between 2nd and 1 first place will be more than 1.

Any place (say i ) can have value atmost 1 more than the LARGEST value at its previous positions (i.e from 1 ..i-1)

  • 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-06-01T12:59:46+00:00Added an answer on June 1, 2026 at 12:59 pm

    Let dp[i, j] = how many possibilities of generating i positions such that the max is j, following the restrictions.

    We have:

    dp[0, 0] = dp[1, 1] = 1
    dp[i, j > i] = dp[i > 0, 0] = 0
    dp[2, 1] = 1*dp[1, 1] + dp[1, 0] <- add 1 at the end
    dp[2, 2] = dp[1, 2] + dp[1, 1] <- add 2 at the end
    
    dp[3, 1] = 1*dp[2, 1] + dp[2, 0] <- add 1 at the end
    dp[3, 2] = 2*dp[2, 2] + dp[2, 1]  <- add 2 at the end
    dp[3, 3] = 3*dp[2, 3] + dp[2, 2] <- add 1, 2 or 3 at the end
    sum = 1 + 2 + 1 + 1 = 5
    
    dp[4, 1] = 1*dp[3, 1] + dp[3, 0]
    dp[4, 2] = 2*dp[3, 2] + dp[3, 1]
    dp[4, 3] = 3*dp[3, 3] + dp[3, 2]
    dp[4, 4] = 4*dp[3, 4] + dp[3, 3] 
    sum = 1 + 6 + 1 + 3 + 3 + 1 = 15 
    
    dp[i, j] = j*dp[i - 1, j] + (1)
               dp[i - 1, j - 1] (2)
    answer = dp[n, 1] + dp[n, 2] + ... + dp[n, n]
    

    (1): We have the max j for the first i - 1 elements already, so we can put anything on position i as long as this doesn’t break the rule. This anything is clearly: 1, ..., j.

    (2): We don’t have the max j for the first i - 1, so we must make it so, by appending j to all those with a max of j - 1. Note that if the max of 1 ... i - 1 is < j - 1, we cannot make the max of 1 ... i to be j while following the restrictions of the problem, so there is no point considering any dp[i - 1, k < j - 1].

    This can be implemented in O(n^2), which should be fast enough for for n up to about 5000 on a decent CPU. The memory used is also O(n^2).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I include a file from a zip file in PHP? For example consider
Consider this example: zh_Hant_HK format = yy'年'M'月'd'日' ah:mm Not sure if you can see
for example if we consider document.createElement() function the parameter can be passed in 3
Consider the example: >>> from sys import maxint >>> type(maxint) <type 'int'> >>> print
I would like to consider a case that i have an html page and
Consider we have: abstract class FlyingObject; case class Rocket(name: String) extends FlyingObject; what is
Consider this example var task =Task.Factory.StartNew(()=>Console.WriteLine(test)); task.ContinueWith(antecendent => { ExceptionProcessor.HandleError(task.Exception.Flatten()); }, TaskContinuationOptions.OnlyOnFaulted); In this
Consider the example plot below. I'd like to make the little boxes around each
Consider the example: IList<string> _lstColl = new[] { Alex, Sam, Gates, Riaz }; I
Consider this example: #include <iostream> class myclass { public: void print() { std::cout <<

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.