2d dp c++ | top down approach
\n\n# Code\n\nstatic const bool __boost = [](){\n    cin.tie(nullptr);\n    cout.tie(nullptr);\n    return ios_base::sync_with_stdio(false);\n}();\nclass Soluti
\n\n# Code\n```\nstatic const bool __boost = [](){\n    cin.tie(nullptr);\n    cout.tie(nullptr);\n    return ios_base::sync_with_stdio(false);\n}();\nclass Solution {\npublic:\n    // map<pair<pair<int,int>,int>,int>m;\n    int dp[2001][2001];\n    int rec (int i, int j,vector<int>&nums,int sum)\n    {\n        \n        if(j-i<=0)\n        {return 1;}\n\n        // if(m.find({{i,j},sum})!=m.end())\n        // return m[{{i,j},sum}];\n        if(dp[i][j]!=-1)\n        return dp[i][j];\n        int a=0;\n        if(nums[i]+nums[i+1]==sum)\n         a = max(a,  rec(i+2,j,nums,sum));\n         if(nums[j]+nums[j-1]==sum)\n         a =max(a,rec(i,j-2,nums,sum)); \n         if(nums[i]+nums[j]==sum) \n         a = max(a,rec (i+1,j-1,nums,sum));\n         \n        // m[{{i,j},sum}]=a+1;\n         return dp[i][j]=a+1;\n\n        \n\n    }\n    int maxOperations(vector<int>& nums) \n    {\n        int ans =0;\n        int i=0,j=nums.size()-1;\n        if(j<3)\n        return 1;\n        memset(dp,-1,sizeof(dp));\n        int a =  rec(i+2,j,nums,nums[0]+nums[1]);\n        \n        int b =  rec(i,j-2,nums,nums[j-1]+nums[j]);          \n\n        int c =  rec (i+1,j-1,nums,nums[i]+nums[j]);        \n\n\n        a=max(a,b);\n        a=max(a,c);\n        return a;\n    }\n};\n```
['C++']