Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
C++ Program to find out the maximum rated parts set
Suppose, there is a manufacturer that makes specific parts for a particular product. The manufacturer has n different variations of the parts, and the parts have a specific rating on three criteria. The ratings of the n products are given in the array 'ratings' where each element is of the format (A, B, C) where A, B, and C are different rating criteria of the product. Now, an OEM wants to buy m parts for each product they make from the manufacturer of the parts. The OEM chooses the parts satisfying the below conditions −
Two or more units of the same part should not be bought.
Choose the set of parts such that the value V is maximized, where V = |total rating of criteria A| + |total rating of criteria B| + |total rating of criteria C|.
We have to find the maximum possible value of V from the parts that the OEM chooses.
So, if the input is like n = 6, m = 4, ratings = {{2, 3, 5}, {3, 5, 2}, {4, 8, 5}, {1, 5, 3}, {7, 2, 7}, {4, 3, 6}}, then the output will be 56.
If the OEM chooses parts 1, 3, 5, and 6, then the total ratings for each category are −
Category A = 2 + 4 + 7 + 4 = 17 Category B = 3 + 8 + 2 + 3 = 16. Category C = 5 + 5 + 7 + 6 = 23 The total value of V is 17 + 16 + 23 = 56.
To solve this, we will follow these steps −
N := 100 Define an array arr of size: 9 x N. Define an array ans. for initialize i := 0, when iExample
Let us see the following implementation to get better understanding −
#includeusing namespace std; const int INF = 1e9; const int modval = (int) 1e9 + 7; #define N 100 int solve(int n, int m, vector > ratings) { int V, arr[9][N] ; vector ans ; for(int i = 0 ; i > ratings = {{2, 3, 5}, {3, 5, 2}, {4, 8, 5}, {1, 5, 3}, {7, 2, 7}, {4, 3, 6}}; cout Input
6, 4, {{2, 3, 5}, {3, 5, 2}, {4, 8, 5}, {1, 5, 3}, {7, 2, 7}, {4, 3,6}}Output
56
