Coloring the blocks question :
Find total cost of coloring each block out of 3 colors such that cost should be minimum and not adjacent
B. There are n blocks placed in a row. Each block must be covered with one of the three colors available, but no two adjacent blocks can be the same color. The cost of coloring each block varies and is given in an array. Given the cost of using each color on each block, determine the minimum cost to color all the blocks.
C. Given colors price in rows, select a min price from the row and no two adjacent rows should have the same minimum price .
input = 3
1 2 3
4 3 2
8 3 2
output: 1+2+3 = 6
D. colored blocks
input = 3
1 2 2
1 2 2
1 2 1
output= 4
E. color cost picker
Input :[1 2 3]
[2 1 3]
[2 1 1]
Output : 1+2+1= 4
Finding the cheapest color and add them
I haven't dot enough information in task A,D,E
# tusk B
def min_costa(cost_of_colors):
current_color = -1
sum = 0
for i in range(len(cost_of_colors)):
min = max(cost_of_colors[i])
for j in range(len(cost_of_colors[i])):
if cost_of_colors[i][j] < min and current_color != j:
min = cost_of_colors[i][j]
current_color = j
sum += min
print(sum)
# tusk C
def min_cost():
number = int(input())
cost_strings = []
min_sums = []
sum = 0
for i in range(number):
cost_strings.append(input().split())
for i in range(number):
min = int(max(cost_strings[i]))
for j in range(0, len(cost_strings[i])):
if int(cost_strings[i][j])<min and int(cost_strings[i][j]) not in min_sums:
min = int(cost_strings[i][j])
min_sums.append(min)
for i in range(number):
sum += min_sums[i]
print(sum)
Comments
Leave a comment