数据输入用的读文件
#include<iostream>
#include<fstream>
using namespace std;
struct TA
{
int k;
long m;
TA():k(0),m(0){}
};
int main()
{
int n;
cin >> n;
ifstream readFile("Test.txt");
char temp;
int* R = new int[n + 1];
for (int i1 = 0; i1 <= n; i1++)
{
readFile >> temp;
R[i1] = int(temp - '0');//输入r[0]到r[n]
}
TA** A = new TA * [n+1];
for (int i2 = 1; i2 <= n; i2++)
{
A[i2] = new TA[n + 1];
}
int j = 0;
for (int r = 2; r <= n; r++)
{
for (int i = 1; i + r - 1 <= n; i++)
{
j = i + r - 1;
long m = A[i][i].m + A[i + 1][j].m + R[i - 1] * R[i] * R[j];
int k = i;
for (int kk = i + 1; kk < j; kk++)
{
long mm = A[i][kk].m + A[kk + 1][j].m + R[i - 1] * R[kk] * R[j];
if (mm < m)
{
m = mm;
k = kk;
}
}
A[i][j].m = m;
A[i][j].k = k;
}
}
cout << A[1][n].m;
delete[] R;
for (int i3 = 1; i3 <= n; i3++)
delete[] A[i3];
delete[] A;
return 0;
}
。