c prgoram for a painter has purchased numerous pajnt bucket to color the bungalow so hr adopts a procedure to maximize the quantity of paint. the paint bucket contains l liter of paint. r liters of paint are drawn out from the paint bucket then the same r liters of turpentine are mixed into the paint the process of removing the paint and mixing turpentine should be always done 2 times the task here is to find out the quantity of paint left in bucket in c language.
Answers
Answer:
Given an integer N and a 2D array cost[][3], where cost[i][0], cost[i][1], and cost[i][2] is the cost of painting ith house with colors red, blue, and green respectively, the task is to find the minimum cost to paint all the houses such that no two adjacent houses have the same color.
Examples:
Input: N = 3, cost[][3] = {{14, 2, 11}, {11, 14, 5}, {14, 3, 10}}
Output: 10
Explanation:
Paint house 0 as blue. Cost = 2. Paint house 1 as green. Cost = 5. Paint house 2 as blue. Cost = 3.
Therefore, the total cost = 2 + 5 + 3 = 10.
Input: N = 2, cost[][3] = {{1, 2, 3}, {1, 4, 6}}
Output: 3
Naive Approach: The simplest approach to solve the given problem is to generate all possible ways of coloring all the houses with the colors red, blue, and green and find the minimum cost among all the possible combinations such that no two adjacent houses have the same colors.
Time Complexity: (3N)
Auxiliary Space: O(1)
Efficient Approach: The above approach can be optimized by using Dynamic Programming as there are overlapping subproblems that can be stored to minimize the number of recursive calls. The idea is to find the minimum cost of painting the current house by any color on the basis of the minimum cost of the other two colors of previously colored houses. Follow the steps below to solve the given problem:
Explanation:
please mark me as a brainleast