C++ Matrix Chain Multiplication
\nclass Solution {\npublic:\n    int dp[502][502];\n    int f(vector<int> &a,int i,int j)\n    {\n        if(i+1==j) return 0;\n        if(dp[i][j]!=-1) return 
```\nclass Solution {\npublic:\n    int dp[502][502];\n    int f(vector<int> &a,int i,int j)\n    {\n        if(i+1==j) return 0;\n        if(dp[i][j]!=-1) return dp[i][j];\n        int res=0;\n        for(int k=i+1;k<j;k++)\n        {\n            res=max(res,(f(a,i,k)+f(a,k,j)+a[i]*a[k]*a[j]));\n        }\n        return dp[i][j] = res;\n    }\n    int maxCoins(vector<int>& a) {\n        a.insert(a.begin(), 1);\n        a.insert(a.end(), 1);\n        int n=a.size();\n        memset(dp,-1,sizeof(dp));\n        return f(a,0,n-1);\n    }\n};\n```
[]