1
The problem asks to do the following: Cut a steel rod of length n to get the maximum possible recipe( Rod Cutting). Present in algorithm with backtraking(already done) and find a solution with greedy algorithm.
Code algorithm made using Backtraking:
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 it is necessary to sort the vector?
Welcome to sopt. Format the code by selecting it and clicking on
{}
– user28595
Greedy Algorithm? This is new for me....
– Thiesen
If I took the partitions with the highest values adding them up and ignoring the other partitions, this would be considered greedy algorithm???
– Joao Joao
Could you send the complete code? With an example of the preference vector
– Marcelo Mikosz
Related: What is a Greedy Algorithm?
– Math