What's Wrong with my solution ? STUCKED


#1

Comment body goes here.

int mergecost(int i,int j,vector &A,bool V[][n],int dp[][n],int n)
{
if(i==j)
return 0;

if(V[i][j])
   return dp[i][j];

V[i][j]=1;
int x=INT_MAX;
int tot=0;
for(int k=i;k<=j;k++)
{
tot+=A[k];
}

for(int k=i;k<j;k++)
{
x=min(x,tot+mergecost(i,k,A,V,dp,n)+mergecost(k+1,j,A,V,dp,n));
}

dp[i][j]=x;
return x;

}
int function(vector &A)
{
int n=A.size();
int i=0;
int j=n-1;
bool V[n][n];
int dp[n][n];
memset(V,0,sizeof(V));

 memset(dp,0,sizeof(dp));
int ans=mergecost(i,j,A,V,dp,n);
return ans;

}