From 8699077cf6a20cd23f761812ed6b68d6a7d5e628 Mon Sep 17 00:00:00 2001 From: Lalit Chaudhary <86573888+CodeLalit007@users.noreply.github.com> Date: Wed, 5 Oct 2022 00:43:12 +0530 Subject: [PATCH] Create knapsnak-greddy-prob.cpp --- .../knapsnak-greddy-prob.cpp | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 algorithms/CPlusPlus/Dynamic-Programming/knapsnak-greddy-prob.cpp diff --git a/algorithms/CPlusPlus/Dynamic-Programming/knapsnak-greddy-prob.cpp b/algorithms/CPlusPlus/Dynamic-Programming/knapsnak-greddy-prob.cpp new file mode 100644 index 00000000..f841b6d9 --- /dev/null +++ b/algorithms/CPlusPlus/Dynamic-Programming/knapsnak-greddy-prob.cpp @@ -0,0 +1,59 @@ +// You are using GCC +#include + +using namespace std; + +int main() +{ + int capacity,items,cur_weight,item; + int used[10]; + float profit; + int i; + int weight[10]; + int value[10]; + + cout<<"Enter the capacity of knapsack:"<>capacity; + + + cout<<"Enter the number of items:"<>items; + + cout<<"Enter the weight and value of "<>weight[i]; + cin>>value[i]; + } + for(i=0;i0) + { + item = -1; + for(i=0;i (float) value[item] / weight[item]))) + item = i; + + used[item] = 1; + cur_weight -= weight[item]; + profit += value[item]; + + if(cur_weight >= 0) + cout<