given two arrays of n numbers, a[] and b[], and a number c, find the largest sum of elements from a[] so the sum of same-indexed elements from b[] don't go over c...
i really have no idea... only recursion works but too slow :( heeeeelp!

What type of problem are you having? Do you not understand how to obtain and evaluate the numbers in a and b? Do you not understand how to write the program so it can be done for any given size of the arrays? Something else?

the algorithm... how to get the value i need...
in an efficient way, cause recursion doesn't work that fast, anyways, if you don't belive i've done it with recursion here's the code:

int rec( int c ) {
    int max = 0;
    for( int i = 0; i < n; i++ ) {
         if( r[i] ) continue;
         r[i] = 1;
         if( c - b[i] >= 0 ) { max >?= rec( c - b[i] ) + a[i]; }
         r[i] = 0;
    }
    return max;
}

r is an array where i mark which i's are already in the call.

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.