# Thread: C , find a subset whose maximum sum

1. ## 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. > I tried to solve this problem but it was difficult for me.
So what was your try?

Subset sum problem - Wikipedia

3. 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. 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.

Popular pages Recent additions