3D Dynamic Programming || C++
Intuition\n Describe your first thoughts on how to solve this problem. \nThere is more suitable ways through using heap, but tried using 3d DP and it worked, bu
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere is more suitable ways through using heap, but tried using 3d DP and it worked, but has exceeded memory problem for large test cases.\n\n# Code\n```\nclass Solution {\npublic:\n    int f(int index, int w, int k, vector<int>& c, vector<int>& p) {\n        int n = c.size();\n        if (index >= n || k == 0) return w;\n\n        if (w >= 0 && dp[index][w][k] != -1) return dp[index][w][k];\n\n        int y = f(index + 1, w, k, c, p);\n\n        int x = 0;\n        if (w - c[index] >= 0)\n            x = f(index + 1, w + p[index], k - 1, c, p);\n\n        return dp[index][w][k] = max(x, y);\n    }\n\n    int findMaximizedCapital(int k, int w, vector<int>& p, vector<int>& c) {\n        int n = c.size();\n        dp.resize(n + 1, vector<vector<int>>(100005, vector<int>(k + 1, -1)));\n        return f(0, w, k, c, p);\n    }\n\nprivate:\n    vector<vector<vector<int>>> dp;\n};\n```
['Array', 'Dynamic Programming', 'C++']