forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
painter_partition.py
33 lines (29 loc) · 930 Bytes
/
painter_partition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def sum(array, initial, to):
total = 0
for i in range(initial, to + 1):
total += array[i]
return total
def partition(array, N, K):
if K == 1:
return sum(array, 0, N - 1)
if N == 1:
return array[0]
best = 100000000
for i in range(1, N + 1):
best = min(best,
max(partition(array, i, K - 1),
sum(array, i, N - 1)))
return best
N, K, T = map(int, input("Enter array size, number
of painters and time: ").split())
x = list(map(int, input("Enter board sizes:").split()))
res = partition(x, N, K)
print("Minimum time required to paint all the boards: " + str(res * T))
"""
Example 1:
Sample Input:
Enter array size, number of painters and time: 2 2 5
Enter board sizes: 1 10
Minimum time required to paint all the boards: 50
Time complexityL O(k*N^3) (Exponential)
"""