Thread: C , find a subset whose maximum sum

  1. #1
    Registered User
    Join Date
    Aug 2019
    Posts
    2

    C , find a subset whose maximum sum

    hi guys,
    I have a problem to solve.
    A = 12000, B is a set of numbers B = {10, 7, 1000, 200, 700, 500, .....}
    B usually has about 300 items numbers.
    It is necessary to find a subset whose maximum sum is less than A = 1200 in number B.[/code]
    I tried to solve this problem but it was difficult for me.
    Please help me.
    Thank you!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,379
    > I tried to solve this problem but it was difficult for me.
    So what was your try?

    Subset sum problem - Wikipedia
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2019
    Posts
    2
    here is a link which solved the task.
    Find the maximum subset XOR of a given set - GeeksforGeeks
    but i only understand in C code only. i am mechanical engineer and learn C code in university.
    Now i want a C code which solve that task and i will translate to autolisp which is a code language in Autocad software.
    Can you understand those code in the link above and translate it to C code.
    My friend said that C code to solve that task is very tough case it do not have support like in C ++
    thanks.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,379
    So?

    The C++ code on that site is near enough to C to be taken as is.
    Even more so if you're using C99, so all those for ( int loops can be taken as is.


    As far as I can see, all you need is to change
    swap(set[index], set[maxInd]);

    to be implemented in C.

    The main wrapper, you just change cout for printf.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 06-15-2019, 12:31 PM
  2. Find Maximum!
    By alireza beygi in forum C Programming
    Replies: 2
    Last Post: 01-06-2012, 05:41 PM
  3. Best way to find maximum number
    By mutombo in forum C Programming
    Replies: 3
    Last Post: 02-27-2009, 04:36 AM
  4. Find all possible subset of a given set
    By Downnin in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 02:03 PM

Tags for this Thread