在递归中求和:它是否总是产生 StackOverflow 错误?
public final static float getAlpha(int t, int i, int N, float[] P, float[][] B, float[][] A, int[] O)
{
float alpha;
if (t==1)
{
alpha = P[i] * B[i][O[0] - 1];
}
else
{
float sum = 0;
int k;
for (k=0; k < N; k++){
sum = sum + (getAlpha(t-1, k, N, P, B, A, O) * A[k][i]);
}
alpha = sum * B[i][O[0] - 1];
}
return alpha;
}
我收到该行的错误:
sum = sum + (getAlpha(t-1, k, N, P, B, A, O) * A[k][i]);
有没有创造性的解决方案?