From 4d3afe204ce87d9b552ad505b1a8518e12e3ed2f Mon Sep 17 00:00:00 2001 From: Karthiks08 <73209015+Karthiks08@users.noreply.github.com> Date: Thu, 22 Oct 2020 10:43:28 +0530 Subject: [PATCH] plz check the udated program check it out --- .../Fractional Knapsack/knapsck1.py | 84 ++++++++++++------- 1 file changed, 55 insertions(+), 29 deletions(-) diff --git a/Greedy algorithm prob. in pyhton/Fractional Knapsack/knapsck1.py b/Greedy algorithm prob. in pyhton/Fractional Knapsack/knapsck1.py index 11def36..d7c4250 100644 --- a/Greedy algorithm prob. in pyhton/Fractional Knapsack/knapsck1.py +++ b/Greedy algorithm prob. in pyhton/Fractional Knapsack/knapsck1.py @@ -1,29 +1,55 @@ -n,W = map(int, input().split(" ")) -maxvalue = 0.000 -nval = 0.000 -value = list() -weight = list() -ratio = list() -for num in range(n): - v,w = map(float, input().split(" ")) - value.append(v) - weight.append(w) - ratio.append(float(v/w)) - #ratio.sort(reverse = True) -while W>0: - try: - num = ratio.index(max(ratio)) - except: - break - if W == weight[num]: - maxvalue+=value[num] - break - elif W>weight[num]: - maxvalue+=value[num] - W-=weight[num] - ratio.remove(max(ratio)) - elif W