囧rz...取的这都是什么破题目啊... 前几日闲来无事,复习线代时对于计算表示鸭梨很大。于是果断写了一个计算行列式的小代码。 算法是用递归实现的最暴力的行列式计算方法。 /* It's just a tool to calculate the matrix. Made by :Kymin.Yu Mail :kymin.yu@gmail.com */ #include<stdio.h> FILE *fin; FILE *fout; int ans=0; void print(int n,int f[][100]); void perm(int n,int *temp,int series[],int f[][100],int boo[]); int dist(int n,int f[]); int main(){ //--------------------initialization------------- fin=fopen("Matrix.txt","r"); int n,i,j,f[100][100]; fscanf(fin,"%d/n",&n); for(i=0;i<n;i++){ for(j=0;j<n;j++) fscanf(fin,"%d",&f[i][j]); fscanf(fin,"/n"); } fout=fopen("Matrix.txt","w"); print(n,f); //----------------------------------------------- int boo[100]={0},series[100]={0},t=0; perm(n,&t,series,f,boo); fprintf(fout,"%d/n",ans); return 1; } void print(int n,int f[][100]){ int i,j; fprintf(fout,"%d/n",n); for(i=0;i<n;i++){ for(j=0;j<n;j++) fprintf(fout,"%d ",f[i][j]); fprintf(fout,"/n"); } fprintf(fout,"The answer of this matrix is "); } void perm(int n,int *temp,int series[],int f[][100],int boo[]){ int i,j,flag=1,t; t=*temp; if(t<=n-1) for(i=0;i<n;i++) if(!boo[i]){ flag=0; boo[i]=1; series[t]=i; t++; perm(n,&t,series,f,boo); t--; boo[i]=0; } int k=1; if(flag){ for(i=0;i<n;i++) k*=f[i][series[i]]; if(dist(n,series))ans+=k; else ans-=k; } } int dist(int n,int f[]){ int i,j,k=0; for(i=0;i<n;i++) for(j=0;j<i;j++) if(f[j]>f[i])k++; if(!(k%2)) return 1; else return 0; } 用空试着把这玩意改成dll..学着做个图形界面..乌拉拉..