hi, I am looking for the code for the following program. Consider a set of elements and a given sum. You need to find a subset of elements whose sum equals or is greater[given there are more than one subset, print the one whose sum is closest to the number] to that number.
PS: it's similar to subset sum problem.
thanks
anaychowdhary
0
Newbie Poster
Recommended Answers
Jump to PostWe don't give away code so that students can cheat on their homework. If you want to put forth some effort in writing this program you'll find help here, otherwise the thread will be in violation of Daniweb's rules and be either closed or deleted.
Jump to Postthe code i have written
Doesn't exist in our perspective until you post it. Show us what you have, tell us what you've tried, and someone will help you move forward.
Jump to Postthere is a simple approach to this problem. start at the begining of the array and sum all of the elements untill you reach your goal. then you need to store the begining and end posistion of that subset. then you will start at the 2nd element of the array …
All 10 Replies
Narue
5,707
Bad Cop
Team Colleague
anaychowdhary
0
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
anaychowdhary
0
Newbie Poster
anaychowdhary
0
Newbie Poster
NathanOliver
429
Veteran Poster
Featured Poster
anaychowdhary
0
Newbie Poster
NathanOliver
429
Veteran Poster
Featured Poster
arkoenig
340
Practically a Master Poster
anaychowdhary
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.