Last active
May 22, 2019 05:21
-
-
Save GitEliteNovice/2ed4f79393b8edb09328c66abae4f089 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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