I have this Java problem, which I suspect is related to a higher level algorithm, but my searches could not come up with anything practical.
You create an array as follows:
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1
Basically, A i, j = A i-1, j-1 + A i-1, j . It should return an element at the index (l, c): for (4, 1) it should return 4, (5, 2) it returns 10, etc. My solution is simple, but not enough:
static long get(int l, int c){ long[][] matrix = new long[l+1][l+1]; matrix[0][0]=1; matrix[1][0]=1; matrix[1][1]=1; for(int i=2;i<=l;i++){ matrix[i][0]=1; for(int j=1;j<=i;j++){ matrix[i][j] = matrix[i-1][j-1]+matrix[i-1][j]; } } return matrix[l][c]; }
It does not work with large values ββof l and c. Using BigInteger does not work. My searches led me to warp and scan loops, but I donβt know where to start. Any guidance in the right direction is truly appreciated.
PS: Sorry for the new vibe, this is my first question!
Mihai source share