Okay I am Solving https://leetcode.com/problems/longest-increasing-subsequence/ My code is Correct and runs fine without memonization(TLE), but after memonized it gives error :
LLVM ERROR: out of memory
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
My code:
class Solution {
public:
int dp[2555][25000005];
int fun(vector<int>& a, vector<int>& v, int i, int count) {
int n = a.size();
if(i == n) return count;
if(dp[i][count] != -1) return dp[i][count];
if(v.back() < a[i]) {
v.push_back(a[i]);
int val1 = fun(a, v, i+1, count+1);
v.pop_back();
int val2 = fun(a,v,i+1,count);
return max(val1, val2);
}
else
return fun(a,v,i+1,count);
}
int lengthOfLIS(vector<int>& a) {
vector<int> v;
v.push_back(INT_MIN);
memset(dp, -1, sizeof(dp));
return fun(a, v, 0, 0);
}
};