Write to your own words: sometimes although a problem to do, but found that writing a problem-solving report, it is very difficult to clearly describe their own ideas. Do a problem-solving report
Not only can consolidate, comb knowledge, but also can deepen understanding. Now I still do very bad, must insist! Come on!
Matrix chain multiplication Problem:
Example:
(the next {P1 should be P2)
void Matrixchain ()
{
int i, j, K, T;
for (i = 1; I <= n; i++)
m[i][i] = 0; The diagonal assignment is 0 because 1 matrices need to be multiplied for 0 times for
(r=2; r<=n; ++r) {for
(i=1; i<=n-r+1; ++i) {
j=i+r-1;
DP[I][J] = INF; The INF represents a large number for
(k=i; k<=j-1; ++k) {
int temp=dp[i][k]+dp[k+1][j]+arr[i-1]*arr[k]*arr[j]; The subscript of the ARR array starts at 0. If starting from 1, each plus 1
if (temp<dp[i][j])
dp[i][j]=temp}
}
}
Rqnoj matrix chain Multiplication http://www.rqnoj.cn/Problem_652.html
This paper url:http://www.bianceng.cn/programming/sjjg/201410/45629.htm