I have written the code but the values not getting inserted into the map. otherwise, it is giving correct output(no. of paths).
#include<bits/stdc++.h>
using namespace std;
static int c=0;
map<pair<int,int>, int> table;
int all_path(int i, int j, int m, int n, map<pair<int,int>, int> table )
{
if(table.find(make_pair(i,j))!=table.end())
{c++; return table[make_pair(i,j)];}
if(i==m-1 && j==n-1)
return 1;
if(i>=m || j>= n)
return 0;
else
return table[make_pair(i,j)]= all_path(i+1, j, m, n,table) + all_path(i, j+1, m,n,table);
}
int main()
{
int i=0, j=0, n, temp,m;
cin>>m>>n;
temp=all_path(i,j,m,n,table);
cout<<temp<<endl; cout<<"saved calls: "<<c;
return 0;
}