I'm know a dynamic programming algorithm to compute the binomial coefficients with two-dimensional array like below . Is there any way to make use of one-dimensional array?
int binomialCoeff(int n, int k)
{
int C[n+1][k+1];
int i, j;
for (i = 0; i <= n; i++)
{
for (j = 0; j <= min(i, k); j++)
{
if (j == 0 || j == i)
C[i][j] = 1;
else
C[i][j] = C[i-1][j-1] + C[i-1][j];
}
}
return C[n][k];
}
{ and}, and the first line of the code in not formatted as code.