C++ | DP Memoization | Simple & Easy Code
\nclass Solution {\npublic:\n    int dpi[1001][4], dpd[1001][4];    \n\tint numTeams(vector<int>& rating) {\n        int n = rating.size();\n        int res = 0
```\nclass Solution {\npublic:\n    int dpi[1001][4], dpd[1001][4];    \n\tint numTeams(vector<int>& rating) {\n        int n = rating.size();\n        int res = 0;\n        \n        memset(dpi, -1, sizeof(dpi)); // to memoize increasing sequence\n        memset(dpd, -1, sizeof(dpd)); // to memoize decreasing sequence\n        \n        for(int i=0; i<n; i++){\n            res += countInc(rating, i, 1, n) + countDec(rating, i, 1, n);  \n        }\n        return res;\n    }\n\t\n    // countInc -> counting the the number of Increasing sequence \n    int countInc(vector<int> &rating, int i, int solCnt, int n){\n        if(dpi[i][solCnt] != -1) return dpi[i][solCnt];\n        if(solCnt == 3) return 1;\n        \n        int cnt = 0;\n        for(int k=i+1; k<n; k++){\n            if(rating[k] > rating[i])\n                cnt += countInc(rating, k, solCnt+1, n);\n        }\n        return dpi[i][solCnt] = cnt;\n    }\n    \n\t// countDec -> counting the the number of decreasing sequence \n    int countDec(vector<int> &rating, int i, int solCnt, int n){\n        if(dpd[i][solCnt] != -1) return dpd[i][solCnt];\n        if(solCnt == 3) return 1;\n        \n        int cnt = 0;\n        for(int k=i+1; k<n; k++){\n            if(rating[k] < rating[i])\n                cnt += countDec(rating, k, solCnt+1, n);\n        }\n        return dpd[i][solCnt] = cnt;\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C']