Recursive brute-force approach to maximum points you can obtain from cards
RE60K has already critiqued your algorithm, so I'll just leave some minor comments on the code style. These comments won't help you beat the time limit, but they are good habits to get into if you're going to take a coding interview someday, for example.

Your class Solution has only public members. Classes with all public members are frequently defined as structs instead.

In fact, your class has no data members! Classes with no data members should probably just be free functions. See The "OO" Antipattern.

Alternatively, you could keep the class as a sort of "namespace" for these two functions, but mark both functions static, so that you don't waste CPU cycles passing around a this pointer that you'll never use. In this case, you should also mark maxScoreUtil as private because it should never be called by anyone outside the class itself.

Alternatively, notice that your current code is paying for a this pointer and also paying to pass dp as the last argument to maxScoreUtil! It should only ever pay for one or the other. If dp always points to the same vector, maybe dp should be a data member of class Solution.

In all of these cases, the elements of cardPoints are not intended to be modified, so you should mark that parameter as const.

To summarize: Right now your code's skeleton is

class Solution {
public:
    int maxScoreUtil(int left, int right,vector&lt;int&gt;&amp; cardPoints, int k,vector&lt;vector&lt;int&gt;&gt;&amp; dp);
    int maxScore(vector&lt;int&gt;&amp; cardPoints, int k);
};


but it should probably be either

class Solution {
    static int maxScoreImpl(int left, int right, const vector&lt;int&gt;&amp; cardPoints, int k, vector&lt;vector&lt;int&gt;&gt;&amp; dp);
public:
    static int maxScore(const vector&lt;int&gt;&amp; cardPoints, int k);
};


or

static int maxScoreImpl(int left, int right, const vector&lt;int&gt;&amp; cardPoints, int k, vector&lt;vector&lt;int&gt;&gt;&amp; dp);
int maxScore(const vector&lt;int&gt;&amp; cardPoints, int k);


or arguably

class Solution {
    vector&lt;vector&lt;int&gt;&gt; dp;
    vector&lt;int&gt; cardPoints;
    int maxScoreImpl(int left, int right, int k);
public:
    static int maxScore(vector&lt;int&gt; cardPoints, int k) {
       int n = cardPoints.size();
       Solution s{ vector&lt;vector&lt;int&gt;&gt;(n+1, vector&lt;int&gt;(n+1, -1)), std::move(cardPoints) };
       return s.maxScoreImpl(0, n-1, k);
    }
};




Notice that I've quietly changed your maxScoreUtil to maxScoreImpl (for "implementation"); that's the usual convention for an internal implementation function. "Util" (for "utilities") is more often used as a namespace or class name for general-purpose utility functions.



    if(k == 0 || left == cardPoints.size() || right &lt; 0)
        return 0;


Surely this should say ... || right &lt; left. Also, here and on the next line, you should get in the habit of curly-bracing any time you indent. It'll save you a lot of debugging someday. Consider the difference between

if (failed) {
    puts("oops, exiting");
    exit(0);
}


and

if (failed)
    puts("oops, exiting");
    exit(0);