I have the following recursive function:
typedef unsigned long long ull;
ull calc(ull b, ull e)
{
if (!b) return e;
if (!e) return b;
return calc(b - 1, e - 1) + calc(b - 1, e) - calc(b, e - 1);
}
I want to implement it with dynamic programming (i.e. using storage). I have tried to use a map<pair<ull, ull>, ull> but it is too slow also. I couldn’t implement it using arrays O(1) too.
I want to find a solution so that this function solves quickly for large b, es.
If a bottom up representation is what you want then this would do fine.
Fill up the table as MBo has shown
This can be done as:
now your answer for any b,e is simply DP[b][e]