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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:34:09+00:00 2026-05-22T01:34:09+00:00

Given set of elements n[1], n[2], n[3], …. n[x] and a number V. (Elements

  • 0

Given set of elements n[1], n[2], n[3], …. n[x] and a number V. (Elements have their own values)

I would like to find all combinations of elements which satisfies the following conditions:

1) Each combination contains specific number of elements (e.g: exactly 5 elements)

Combination#1: n[1], n[2], n[21], n[22], n[24]

Combination#2: n[1], n[2], n[12], n[15], n[33]

……

2) Sum of elements values in combination must be smaller than given number V (e.g V = 100)

Combination#1: n[1] + n[2] + n[21] + n[22] + n[24] < 100

Combination#2: n[1] + n[2] + n[12] + n[15] + n[33] < 100

……

I am trying to write a c# program which computes these elements. But language is not important, any algorithm satisfies these conditions is acceptable!

Thanks

  • 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-22T01:34:09+00:00Added an answer on May 22, 2026 at 1:34 am

    Since you will probably have to use brute force anyway, you can solve your problem with the following approach:

    First of all, sort your input set S.

    Then remove all elements from S which are greater than V - 4*|min| (where |min| is the absolute value of the smallest element), because they won’t appear in any of your solutions anyway. Depending on your exact problem specification, this optimization may be improved further.

    Now you generate all sums of length C of elements in S, starting with the smallest possible numbers (remember that S is sorted).

    If the result is smaller than V, add it to your solution set and increase the last summand.

    Otherwise, set the previously increased summand and all summands after that one to their smallest possible values and increase the summand just before that.

    You can stop if all summands have reached their highest possible values. You may be able to stop long before that, which is left as an exercise to the reader due to my sloppy English.

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

Sidebar

Related Questions

I would like to find all the possible combinations of weighted elements in a
Given a set of phrases, i would like to filter the set of all
I have to solve the following optimization problem: Given a set of elements (E1,E2,E3,E4,E5,E6)
Given a set** S containing duplicate elements, how can one determine the total number
I have an array with a set of elements. I'd like to bring a
I'm trying to use XPath to find all elements that have an element in
I have a set called ISET; with a long list of 3-letter elements like:
Imagine you have a set of five elements (A-E) with some numeric values of
Is there an application , which can parse a given set of stored procedures
Given a set of words, we need to find the anagram words and display

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.