I was trying to solve a Lattice paths problem using dynamic programming method.
Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.
How many routes are there through a 2020 grid?
Here is the code I have written to solve this question. Where am I going wrong. I seem to get wrong output every time. Am I crossing some boundaries in variable data types?
#include <stdio.h>
int count = 0;
int limita,limitb;
long long int cache[20][20];
unsigned long long int start(int a,int b)
{
unsigned int long long i = 0;
if(a == limita && b == limitb)
return 1;
if(cache[a][b] != -1)
return cache[a][b];
if(a != limita)
i += start(a+1, b);
if(b != limitb)
i += start(a, b+1);
cache[a][b] = i;
return i;
}
int main(void)
{
limita = limitb = 19;
int i,j;
for(i = 0; i < 20; i++)
for(j = 0; j <20;j++)
cache[i][j] = -1;
unsigned long long int number = start(0,0);
printf("The number of ways to reach the end is %llu\n",number);
return 0;
}
Please help me out

A grid of size 1*1:
A grid of size 2*2:
…
Your algorithm seems to be OK, but you’re counting edges wrong.