Q163
Consider the following dynamic programming implementation of the matrix chain problem: #include #include int mat_chain_multiplication(int *mat, int n) int arr[n][n]; int i,k,row,col,len; for(i=1;i<n;i++) arr[i][i] = 0; for(len = 2; len < n; len++) for(row = 1; row <= n - len + 1; row++) col = row + len - 1; arr[row][col] = INT_MAX; for(k = row; k <= col - 1; k++) int tmp = ________________________; if(tmp < arr[row][col]) arr[row][col] = tmp; return arr[1][n - 1]; int main() int mat[6] = 20,5,30,10,40; int ans = mat_chain_multiplication(mat,5); printf("%d",ans); return 0; Which of the following lines should be inserted to complete the above code?
A.
arr[row][k] - arr[k + 1][col] + mat[row - 1] * mat[k] * mat[col];
B.
arr[row][k] + arr[k + 1][col] - mat[row - 1] * mat[k] * mat[col];
C.
arr[row][k] + arr[k + 1][col] + mat[row - 1] * mat[k] * mat[col];
AnswerD.
arr[row][k] - arr[k + 1][col] - mat[row - 1] * mat[k] * mat[col];
Answer: Option C
Solution
Answer: Option C
No explanation is given for this question Let's Discuss on Board