只想用指针传参但是报错 cannot convert parameter 1 from 'int [10][10]' to 'int **'如何解决
voidTrace_Back(int**s,inti,intj){if(i==j)return;Trace_Back(s,i,s[i][j]);Trace_Back(s,...
void Trace_Back(int** s,int i,int j){
if(i==j)
return;
Trace_Back(s,i,s[i][j]);
Trace_Back(s,s[i][j]+1,j);
cout<<","<<s[i][j]<<","<<" ";
}
/*
*@matrix_param 矩阵的参数行或是列
*@matrix_num 矩阵的数量
*/
void MatrixCal(int* matrix_param,int matrix_num){
int beststep[10][10];
int duandian[10][10];
memset(beststep,0,sizeof(beststep));
memset(duandian,0,sizeof(duandian));
for(int column=1;column<=matrix_num;column++)
for(int line=1;line<=matrix_num-column+1;line++){
if(column==1)
beststep[column][line]=0;
if(column>1){
double temp_beststep=100000000000;
int temp_data=0;
for(int compare_time=1;compare_time<column;compare_time++){
temp_data=beststep[compare_time][line]+beststep[column-compare_time][compare_time+line]+matrix_param[line-1]*matrix_param[compare_time+line-1]*matrix_param[line+column-1];
if(temp_data<temp_beststep){
temp_beststep=temp_data;
duandian[column][line]=compare_time+line-1;
}
}
beststep[column][line]=temp_beststep;
}
}
for(int i=0;i<10;i++){
for(int j=0;j<10;j++)
cout<<beststep[i][j]<<" ";
cout<<endl;
}
for(int i=0;i<10;i++){
for(int j=0;j<10;j++)
cout<<duandian[i][j]<<" ";
cout<<endl;
}
Trace_Back(duandian,1,matrix_num);
system("pause");
} 展开
if(i==j)
return;
Trace_Back(s,i,s[i][j]);
Trace_Back(s,s[i][j]+1,j);
cout<<","<<s[i][j]<<","<<" ";
}
/*
*@matrix_param 矩阵的参数行或是列
*@matrix_num 矩阵的数量
*/
void MatrixCal(int* matrix_param,int matrix_num){
int beststep[10][10];
int duandian[10][10];
memset(beststep,0,sizeof(beststep));
memset(duandian,0,sizeof(duandian));
for(int column=1;column<=matrix_num;column++)
for(int line=1;line<=matrix_num-column+1;line++){
if(column==1)
beststep[column][line]=0;
if(column>1){
double temp_beststep=100000000000;
int temp_data=0;
for(int compare_time=1;compare_time<column;compare_time++){
temp_data=beststep[compare_time][line]+beststep[column-compare_time][compare_time+line]+matrix_param[line-1]*matrix_param[compare_time+line-1]*matrix_param[line+column-1];
if(temp_data<temp_beststep){
temp_beststep=temp_data;
duandian[column][line]=compare_time+line-1;
}
}
beststep[column][line]=temp_beststep;
}
}
for(int i=0;i<10;i++){
for(int j=0;j<10;j++)
cout<<beststep[i][j]<<" ";
cout<<endl;
}
for(int i=0;i<10;i++){
for(int j=0;j<10;j++)
cout<<duandian[i][j]<<" ";
cout<<endl;
}
Trace_Back(duandian,1,matrix_num);
system("pause");
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询