I'm trying to understand the text justification problem the program must return the minimum badness but it return negative value i don't know why
#include <bits/stdc++.h>
using namespace std;
string text[4] = {"-1", "sayed", "play", "chess"};
int N = 4;
int width = 10;
//int store[4];
int badness(int i, int j){
int sum = 0;
for(i ; i <= j ; i++)
sum += text[i].size();
if(j-i > 1 ) sum += j - i;
return pow((width - sum),3);
}
int jt(int i){
if (i == N + 1) return 0;
int m = (int)1e8;
for(int j = i + 1 ; j <= N + 1 ; j++) //why to N+1 and why we start from i+1
m = min(m, jt(j)+badness(i, j-1));
return m;
}
int main(){
cout << jt(0) << endl;
}
Comments
Post a Comment