Sorry, I passed my code to english.
INT_MAX is from limits.h library.
these are my two methods, the copy method and the algorithm method.
int* copy(int* K, int n){
int* L = new int[n];
for(int k = 0; k < n; k++){
L[k] = K[k];
}
return L;
}
int mfPD(int * K, int n){
if(n == 2){
return K[1]*K[0];
}else if(n == 1){
return 0;
}
int C[n][n];
for(int i = 1; i < n; i++)
C[i][i] = 0;
for(int i = n-1; i >= 1; i--){
int* L = copy(K, n);
for(int j = i+1; j <= n-1; j++){
int less = INT_MAX;
for(int k = i; k <= j-1; k++){
int cost = L[k]*L[k-1];
int newcolor = (L[k]+L[k-1])%100;
L[k] = L[k-1] = newcolor;
int q = C[i][k]+C[k+1][j] + cost;
if(q < less)
less = q;
}
C[i][j] = less;
}
}
return C[1][n-1];
}
and here is the main:
int main(){
while(true){
int n;
cin >> n;
if(!cin) break;
int* colors = new int[n];
for(int i = 0; i<n; i++){
cin >> colors[i];
}
int smoke = mfPD(colors, n);
cout << smoke << endl;
// cout << mf(cores, 0, n-1, n) << endl;
}
return 0;
}