#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int a[N];
int dp[N][N];
int Csum(int z, int y){
int sum = 0;
for(int i = z; i <= y; i++){
sum += a[i];
sum %=100;
}
return sum;
}
int main(){
int n;
while(cin >> n){
for(int i = 1; i <= n; i++)
cin >> a[i];
dp[0][0] = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(i == j)
dp[i][j] = 0;
else
dp[i][j] = INT_MAX;
for(int k = i; k < j; k++){
int x = Csum(i, k);
int y = Csum(k+1,j);
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + x * y);
}
}
}
cout << dp[1][n] << endl;
}
return 0;
}
I'm using a different approach than most people; so I'm not being able to figure out the bug in my code. Any help would be appreaciated