You had to paint N boards of lenght {A0, A1, A2 ... AN-1}. There is K painters available and you is also given how much time a painter takes to paint 1 unit of board. You have the-get this job do as soon as possible under the constraints that any painter would only paint continues sections S of board, say board {2, 3, 4} or only board {1} or nothing and not board {2, 4, 5}.
We define M[n, K] as the optimum cost of a partition arrangement with n total blocks from the first block and k patitions, so
N n-1
M[n, K] = min {max {m[j, K1∑ Ai}} J=1 i=j
The base cases is:
m[1, K] = A0 1Σ Ai
I=0
Therefore, the Brute force solution is:
intSumintA[],int from,intTo ) { intTotal =0; for(inti = from; I <= to; i++) Total+=A[i]; returnTotal ;}intPartitionintA[],intNintk) { if(N <=0|| K <=0) return-1; if(n = =1) returna[0]; if(k = =1) returnSUM (A,0, N-1); intBest =Int_max; for(intj =1; J <= N; J + +) Best= Min (Best, Max (partition (A, J, K1), SUM (A, J, N1))); returnBest ;}
The Painter ' s Partition problem part I