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<