Can anyone help me with the greedy algorithm problem?

1

The problem asks you to do the following: Cut a steel rod of length n to obtain the maximum possible revenue (Rod Cutting). Present in algorithm with backtracking (I already did) and find a solution with greedy algorithm.

Algorithm code made using Backtracking:

int max(int a, int b) { return (a > b)? a : b;}

int cutRod(int price[], int n)
{
   if (n <= 0)
     return 0;
   int max_val = INT_MIN;

   for (int i = 0; i<n; i++)
        max_val = max(max_val, price[i] + cutRod(price, n-i-1));

   return max_val;
}

To make the code using greedy algorithm is it necessary to sort the vector?

    
asked by anonymous 09.05.2016 / 14:27

0 answers