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

  • Home
  • SEARCH
  • 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 7834629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:15:47+00:00 2026-06-02T13:15:47+00:00

I just find a problem like this Give you N different integers, do you

  • 0

I just find a problem like this

“Give you N different integers, do you know how many different sequences that the difference between every adjacent pair of numbers is larger than 1?”

And when the integers are “1 2 3”, then the answer is zero, when the integers are “5 3 1”, then the answer is 6, for “1 3 5” “1 5 3” “3 1 5” “3 5 1” “5 1 3” “5 3 1” satisfy the problem, I just tried all I could do but I couldn’t solve it, so my question is, how to write a algorithm to solve it.

Thankyou.

Here is my program

int n;bool vi[30];int a[30];int b[30];int counter = 0;
void dfs(int k)
{
    if ( k == n)
    {
        for (int i = 2; i <= n; i ++)
            if (fabs(b[i] - b[i - 1]) <= 1) return ;
        counter ++;
        return ;
    }
    for (int i = 0; i < n; i ++)
    {
    if (!vi[i])
    {
        b[k + 1] = a[i];
        vi[i] = true;
        dfs(k + 1);
        vi[i] = false;
        }
    }
}
int main (void)
{
        cin >> n;
        for (int i = 0; i < n; i ++)
            cin >> a[i];
        memset(vi, 0, sizeof(vi));
        for (int i = 0; i < n; i ++)
        {
            vi[i] = true;b[1] = a[i];dfs(1);vi[i] = false;
        }
        cout << counter << endl;
    return 0;
}
  • 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-02T13:15:50+00:00Added an answer on June 2, 2026 at 1:15 pm

    The answer to the question, “How many different sequences are there…” can be solved without enumerating every combination. Which is a good thing, because 25! is approximately 1.55 x 10^24, or way more than any existing computer is going to enumerate in a second. Or in a year.

    This is a math problem, specifically combinatorics. See http://en.wikipedia.org/wiki/Combinatorics and possibly http://en.wikipedia.org/wiki/Combinations for information on how you would go about solving the problem.

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

Sidebar

Related Questions

I have this problem and i just cannot find a solution to it. I
First of all, there are many questions just like this, and perhaps some OPs
I'm trying to write (or just find an existing) PHP method that can take
I have looked everywhere for this and just cannot find the answer. I have
Can anyone psuedo a solution to my problem, or just give discussion to help
I have a problem that I haven't been able to find a solution to,
This is a very trivial problem but I can't seem to find a way
I couldn't find a question that would fit this purpose, so I'm asking it.
Just curious to find out exactly what problems I'll cause myself if I include
I just find out about the power of date js, And its great!!! As

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.