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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:07:53+00:00 2026-05-13T14:07:53+00:00

The problem is simpler than knapsack (or a type of it, without values and

  • 0

The problem is simpler than knapsack (or a type of it, without values and only positive weights). The problem consists of checking whether a number can be a combination of others. The function should return true or false.

For example,

112 and a list with { 17, 100, 101 } should return false, 469 with the same list should return true, 35 should return false, 119 should return true, etc…

Edit: subset sum problem would be more accurate for this than knapsack.

  • 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-13T14:07:53+00:00Added an answer on May 13, 2026 at 2:07 pm

    An observation that will help you is that if your list is {a, b, c…} and the number you want to test is x, then x can be written as a sum of a sublist only if either x or x-a can be written as a sum of the sublist {b, c, …}. This lets you write a very simple recursive algorithm to solve the problem.

    edit: here is some code, taking into account the comments below. Not tested so probably buggy; and not necessarily the fastest. But for a small dataset it will get the job done neatly.

    bool is_subset_sum(int x, std::list::const_iterator start, std::list::const_iterator end)
    {
      // for a 1-element list {a} we just need to test a|x
      if (start == end) return (x % *start == 0); 
    
      // if x is small enough  we don't need to bother testing x - a
      if (x<a) return is_subset_sum (x, start+1, end);
    
      // the default case. Note that the shortcut properties of || means the process ends as soon as we get a positive.
      return (is_subset_sum (x, start+1, end) || is_subset_sum (x-a, start, end));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may end up being a much simpler problem than I'm making it out
My problem is a bit more complex than using the following simple JavaScript code:
Simple problem that I can't figure out... How can I print a '%' character
simple problem with a simple question. I have a string, in C# i can
The problem seems simple, but I can't seem to find a way to implement
Sorry or the confusing title! It's actually a lot simpler than it sounds. I've
Im reposting this problem in a simpler fashion, as I was getting comments about
This must be simpler than I'm making it out to be. Not sure what's
Really simple problem: I want to split a connection string into its keyword /
Simple problem (I think): I want to be able to invoke a click method

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.