Easy soln using cpp


#1
#define ff first
#define ss second
int Solution::maxcoin(vector<int> &A) 
{   int n=A.size();
    pair<int,int> dp[n][n];
    for(int s=1;s<=n;s++)
    {
        for(int i=0;i+s-1<n;i++)
        {
            if(s==1)
            {
                dp[i][i].ff=A[i];
                dp[i][i].ss=0;
            }
            else
            {
                dp[i][i+s-1].ff=max(A[i]+dp[i+1][i+s-1].ss,A[i+s-1]+dp[i][i+s-2].ss);
                if(A[i]+dp[i+1][i+s-1].ss>A[i+s-1]+dp[i][i+s-2].ss)
                dp[i][i+s-1].ss=(dp[i+1][i+s-1].ff);
                else
                dp[i][i+s-1].ss=(dp[i][i+s-2].ff);
            }
        }
    }
    return dp[0][n-1].ff;
}