MLE Memory Limit Exceeded

@alamsarfraz422 value of n can be upto 1000000000 we can not create a array of this size so use a map as all the positions of 1 to n are not possible only realted to /2 /3 and /4 are possible so it is better to use map here just create a map instead of dp and whole thing will work fine
using namespace std;
#include <bits/stdc++.h>
#define ll long long
map<ll, ll> mp;
ll cal(ll n)
{
if (n == 1 || n == 0)
return n;
else if (mp.count(n))
return mp[n];
return mp[n] = max({n, cal(n / 2) + cal(n / 3) + cal(n / 4)});
}
void solve()
{
int n;
cin >> n;
cout << cal(n) << endl;
}
int main()
{

int t = 1;

while (t--)
    solve();
return 0;

}
this is the implemented code it will work fine
if your dout clear mark it as solved and rate my experience

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.