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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:25:42+00:00 2026-06-13T13:25:42+00:00

I need an algorithm for this problem: Given a set of n natural numbers

  • 0

I need an algorithm for this problem:

Given a set of n natural numbers x1,x2,…,xn, a number S and k. Form the sum of k numbers picked from the set (a number can be pick many times) with sum S.

Stated differently: List every possible combination for S with Bounds: n<=256, x<=1000, k<=32

E.g.

  problem instance: {1,2,5,9,11,12,14,15}, S=30, k=3
  There are 4 possible combinations
  S=1+14+15, 2+14+14, 5+11+15, 9+9+12.   

With these bounds, it is unfeasible to use brute force but I think of dynamic programming is a good approach.

The scheme is: Table t, with t[m,v] = number of combinations of sum v formed by m numbers.

1. Initialize t[1,x(i)], for every i.   
2. Then use formula t[m,v]=Sum(t[m-1,v-x(i)], every i satisfied v-x(i)>0), 2<=m<=k.   
3. After obtaining t[k,S], I can trace back to find all the combinations.  

The dilemma is that t[m,v] can be increase by duplicate commutative combinations e.g., t[2,16]=2 due to 16=15+1 and 1+15. Furthermore, the final result f[3,30] is large, due to 1+14+15, 1+15+14, …,2+14+14,14+2+14,…

How to get rid of symmetric permutations? Thanks in advance.

  • 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-13T13:25:45+00:00Added an answer on June 13, 2026 at 1:25 pm

    You can get rid of permutations by imposing an ordering on the way you pick elements of x. Make your table a triple t[m, v, n] = number of combinations of sum v formed by m numbers from x1..xn. Now observe t[m, v, n] = t[m, v, n-1] + t[m-1, v-x_n, n]. This solves the permutation problem by only generating summands in reverse order from their appearance in x. So for instance it’ll generate 15+14+1 and 14+14+2 but never 14+15+1.

    (You probably don’t need to fill out the whole table, so you should probably compute lazily; in fact, a memoized recursive function is probably what you want here.)

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

Sidebar

Related Questions

I need an algorithm which given a list L and a number N ,
I need an algorithm that identifies all possible combinations of a set of numbers
I need to print all the prime numbers less than a given number n.
Hey, Here is my problem, Given a set of documents I need to assign
i need to implement a genetic algorithm customized for my problem (college project), and
So, I have this algorithm to calculate cross-section of 3D shape with plane given
I will phrase the problem in the precise form that I want below: Given
I'm trying to find a solution to this problem: Given a IEnumerable< IEnumerable< int>>
the question is like this: there is a sorted list of n numbers. Given
Problem Given a number n, 2<=n<=2^63. n could be prime itself. Find the prime

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.