Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Greedy Knapsack
{
for i=1 to n //step1
{
compute pi/wi; //step2
}
sort objects in non- increasing order p/w; //step3
for i=1 to n //step4
if(m>0 && wi<=m) //step5
m = m - wi; //step6
P = P + pi; //step7
else //step8
break; //step9
if(m>0) //step10
P=P+ pi*(m/wi); //step11
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.