计算矩阵点乘函数步总数的公式

#include<stdio.h>

int count=0;

#define MAX_SIZE 2

void dot_p(int a[][MAX_SIZE], int b[][MAX_SIZE],
		 int c[][MAX_SIZE], int rows, int cols);

int main(void)
{
		int a[MAX_SIZE][MAX_SIZE]={{9,8},{2,3}};
		int b[MAX_SIZE][MAX_SIZE]={{6,7},{8,9}};
		int c[MAX_SIZE][MAX_SIZE];
		
		dot_p(a,b,c, MAX_SIZE,MAX_SIZE);
		printf("%d
",count);
		return 0;
}
void dot_p(int a[][MAX_SIZE], int b[][MAX_SIZE],
		 int c[][MAX_SIZE], int rows, int cols)
{
	int i,j,k,g;
	for(k=0; k<rows; k++){     //se:1 频率:n+1 步数:n+1
			count+=2;          
		for(i=0; i<rows; i++){ //se:1 频率:n(n+1) 步数:n²+n
			count+=3;          
//			c[k][i]=0;         //se:1 频率:n²  步数:n²
			for(j=0; j<rows; j++){ //se:1 频率:n²(n+1) 步数:n^3+n²
				count+=4;
//				g=a[k][j]*b[j][i];
//		        c[k][i]+=g;
//	            printf("g:%d %d
", g, c[k][i]);
							  //se:1 频率:3n² 步数:3n² 
							  //公式:1+2n+3n²+4n^3
			}
		}
	}
	count++;
}

原文地址:https://www.cnblogs.com/WALLACE-S-BOOK/p/9732310.html