Nisha Patel
Summary
Let’s assume:
Integer- value, weight
Function- fractionalKnapsack
Considering three parameters:
Maximum weight capacity- w
Array of items- a
Number of items- n
Solution
Explanation
Inside the function:
A vector of pairs, where the first element is the per unit value of an item (value/weight), and the second element is the actual item, is created. This vector is named v.
The function cmp is a static comparison function used to sort the vector v in non-increasing order based on per unit value.
Suggested blogs:
>Find the number of pairs of elements whose sum is equal to K using C++
>How to check whether string is palindrome or not using C++
>How to determine the smallest possible size of a vertex cover using C++
>Build an Electron application from scratch
>Building Web API using ASP.NET (C#)
>Built Web API using ASP.NET (C#)