出于某种原因,我在第 15 行收到错误“没有对 'OptimalBinarySearchTree' 的匹配函数调用”。我不确定它是否与我传递数组指针的方式有关,或者我是否遗漏了某些内容。我以前从未尝试过传递二维数组,所以它可能会搞砸。
#include <iostream>
using namespace std;
void OptimalBinarySearchTree(int n, int *P[n], int (*values)[n][n], int (*roots)[n][n]);
int main()
{
const int n = 18;
char A[n] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R'};
int P[n] = {995,22,23,562,33,8,60,118,30,723,807,626,15,89,21,128,626,621};
int values[n][n];
int roots[n][n];
OptimalBinarySearchTree(n, P, values, roots);
return 0;
}
void OptimalBinarySearchTree(int n, int *P[n], int (*values)[n][n], int (*roots)[n][n])
{
for (int i = 1; i <= (n+1); i++)
{
(*values)[i][i] = 0;
}
for (int i = 1; i <= n; i++)
{
(*values)[i][i] = *P[i];
(*roots)[i][i] = i;
}
for (int d = 1; d <= (n-1); d++)
{
for (int i = 1; i <= (n-d); i++)
{
int j = i + d;
int sumP = 0;
int minValue = 999999999;
int minRoot = 0;
for (int k = i; k <= j; k++)
{
sumP += *P[k];
int value = (*values)[i][k-1] + (*values)[k+1][j];
if (value < minValue)
{
minValue = value;
minRoot = k;
}
}
(*values)[i][j] = sumP + minValue;
(*roots)[i][j] = minRoot;
}
}
};
任何帮助,将不胜感激。谢谢,