Maximise profits of opening N shops in a commercial complex
Given an integer N representing the number of shops and a 2D array profit[][3], where profit[i][0], profit[i][1], and profit[i][2] represent the profit of opening the ith shop offering services like food, clothing, and electronics respectively, the task is to find the maximum profit by opening all the shops in a way that neighbouring shops offer different services, i.e., no adjacent shops can provide the same service.
Input: N = 3, profit[][3] = {{14, 2, 11}, {11, 14, 5}, {14, 3, 10}}
Output: 42
Explanation:
Open Shop 0 as Food shop. Profit = 14. Open Shop 1 as clothing shop. Profit = 14. Open Shop 2 as Food shop Profit = 14.
Therefore, the total profit = 14 + 14 + 14 = 42.
Input: N = 2, profit[][3] = {{1, 2, 3}, {1, 4, 6}}
Output: 8