#include<iostream>
using namespace std;
#define MAXLEN 100
void MatrixChain(int p[MAXLEN],int n,int m[MAXLEN][MAXLEN],int s[MAXLEN][MAXLEN])
{
for (int i = 1; i <= n; i++)
m[i][i] = 0;
for (int r = 2; r <= n; r++){
for (int i = 1; i <= n - r+1; i++) {
int j=i+r-1;
m[i][j] = m[i+1][j]+ p[i-1]*p[i]*p[j];
s[i][j] = i;
for (int k = i+1; k < j; k++) {
int t = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
if (t < m[i][j]) {
m[i][j] = t;
s[i][j] = k;
}
}
}
}
}
void traceback(int i,int j,int s[MAXLEN][MAXLEN])
{
矩阵连乘---求几个矩阵乘积的最小值
最新推荐文章于 2020-12-08 19:29:13 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)