Help me to fix this code

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
solution(int n,int a[])
{
    int dp[n][n];

    for(int len =2;len<n;len++)
    {
       int col = len;

        for(int row=0;row<n-len;row++,col++)
        {
           dp[row][col]=INT_MAX;
           for(int k=row+1; k<col;k++)
           {
               dp[row][col]=min(dp[row][col],dp[row][k]+dp[k][col]+a[row]*a[k]*a[col]);

           }
           col++;


        }
    }
    return dp[0][n-1];


}

int main()
{
    int n ;
    cout<<"Enter the number of matrics ";
    cin>>n;
    int a[n];
    cout<<"enter the dimension of the matrics ";
    for(int i =0;i<n;i++)
    {
        cin>>a[i];

    }
    int result=solution(n,a);
    cout<<"minimum cost"<<result<<endl;

}

Hi there and welcome to our community!

Your request is a little vague. What is the issue with the code? What is it that you are expecting it to do and how is it misbehaving for you?

1 Like

Sir it is giving me garbage value in minimum cost. Please reply sir as soon as possible

Whilst we’re here primarily to assist people with learning the FCC Curriculum, there may be someone here who may be able to assist.

FCC only recently introduced a foundational C# certification, as the curriculum here is primarily focused on web development, using HTML/CSS, Javascript and Python.

I’m not (yet) au fait with C programming of any variety however, so I can’t be of much use, sorry.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.