I was trying this [question](https://atcoder.jp/contests/abc275/tasks/abc275_d)↵
↵
and for some reason that i dont understand my code doesn't work that is following.↵
↵
↵
~~~~~↵
int rec(int n, vector<int>&v){↵
if(n == 0){↵
return 1;↵
}↵
↵
if(v[n] != -1){↵
return v[n];↵
}↵
return v[n] = rec(floor(n/2),v) + rec(floor(n/3),v);↵
}↵
↵
void solve() {↵
read(n);↵
vector<int>v(n+1,-1);↵
cout<<rec(n,v)<<endl;↵
↵
}↵
↵
~~~~~↵
↵
↵
↵
but the following code which has the same logic works. ↵
↵
↵
↵
↵
~~~~~↵
map<ll, ll> mp;↵
ll calc(ll x) {↵
if (x == 0)return 1;↵
if (mp.find(x) != mp.end())return mp[x];↵
ll res = calc(x / 2) + calc(x / 3);↵
return mp[x] = res;↵
}↵
void solve() {↵
ll n; cin >> n;↵
cout << calc(n) << "\n";↵
}↵
~~~~~↵
↵
↵
↵
↵
and for some reason that i dont understand my code doesn't work that is following.↵
↵
↵
~~~~~↵
int rec(int n, vector<int>&v){↵
if(n == 0){↵
return 1;↵
}↵
↵
if(v[n] != -1){↵
return v[n];↵
}↵
return v[n] = rec(floor(n/2),v) + rec(floor(n/3),v);↵
}↵
↵
void solve() {↵
read(n);↵
vector<int>v(n+1,-1);↵
cout<<rec(n,v)<<endl;↵
↵
}↵
↵
~~~~~↵
↵
↵
↵
but the following code which has the same logic works. ↵
↵
↵
↵
↵
~~~~~↵
map<ll, ll> mp;↵
ll calc(ll x) {↵
if (x == 0)return 1;↵
if (mp.find(x) != mp.end())return mp[x];↵
ll res = calc(x / 2) + calc(x / 3);↵
return mp[x] = res;↵
}↵
void solve() {↵
ll n; cin >> n;↵
cout << calc(n) << "\n";↵
}↵
~~~~~↵
↵
↵
↵