Simple c++ solution
\n\n# Code\n\nclass Solution {\npublic:\n    int maxCoins(vector<int>& nums) {\n        int n=nums.size();\n        nums.push_back(1);\n        nums.insert(nums
\n\n# Code\n```\nclass Solution {\npublic:\n    int maxCoins(vector<int>& nums) {\n        int n=nums.size();\n        nums.push_back(1);\n        nums.insert(nums.begin(),1);\n        vector<vector<int>>dp(n+2,vector<int>(n+2,0));\n        for(int i=n;i>=1;i--){\n            for(int j=1;j<=n;j++){\n                if(i>j) continue;\n                int maxi=INT_MIN;\n                for(int ind=i;ind<=j;ind++){\n                    int cost=nums[i-1]*nums[ind]*nums[j+1]+dp[i][ind-1]+dp[ind+1][j];\n                    maxi=max(maxi,cost);\n        }\n        dp[i][j]=maxi;\n            }\n        }\n        return dp[1][n];\n    }\n};\n```
['C++']