n^3logn非常显然。所以要用一种因为这个矩阵是一个循环矩阵,所以只要知道第一行就可以知道所有行了。 C[i][j]=C[i-1][j-1];
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <algorithm> 5 using namespace std; 6 const int Maxn=1010; 7 int n,m,k; 8 struct Matrix{double a[Maxn];}Ori,Bas,Ans; 9 inline Matrix operator * (Matrix A,Matrix B) 10 { 11 Matrix C; memset(C.a,0,sizeof(C.a)); 12 for (int i=1;i<=n;i++) 13 for (int j=1;j<=n;j++) C.a[i]+=A.a[j]*B.a[(i-j+n+1)%n==0?n:(i-j+n+1)%n]; 14 return C; 15 } 16 inline Matrix Pow(Matrix Base,int Exp) 17 { 18 Matrix Ret; memset(Ret.a,0,sizeof(Ret.a)); Ret.a[1]=1; 19 while (Exp) 20 { 21 if (Exp&1) Ret=Ret*Base; 22 Base=Base*Base; Exp>>=1; 23 } 24 return Ret; 25 } 26 int main() 27 { 28 scanf("%d%d%d",&n,&m,&k); 29 for (int i=1;i<=n;i++) scanf("%lf",&Ori.a[i]); 30 Bas.a[1]=(double)(m-1)/(double)m; 31 Bas.a[2]=1/(double)m; 32 Bas=Pow(Bas,k); 33 Ans=Bas*Ori; 34 for (int i=1;i<=n;i++) printf("%.3lf ",Ans.a[i]); 35 return 0; 36 } 37
C[1][i]=A[1][k]*B[k][i]; 就可以转换为 C.a[1][i]=A[1][k]*B[1][i-k+1];
类似题目:POJ 3150 HDU 2276 HDU 4576