标签:style repr 计算 lines cas math pre sample roc
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4307 Accepted Submission(s): 2586
1 //普通递推会超时,用矩阵乘法。 2 #include<bits\stdc++.h> 3 using namespace std; 4 int a[12],f[12]={9,8,7,6,5,4,3,2,1,0}; 5 int k,m; 6 struct Lu 7 { 8 int mp[12][12]; 9 }L1; 10 void init() 11 { 12 memset(L1.mp,0,sizeof(L1.mp)); 13 for(int i=1;i<=9;i++) 14 { 15 L1.mp[i][i-1]=1; 16 } 17 for(int i=0;i<=9;i++) 18 { 19 L1.mp[0][i]=a[i]; 20 } 21 } 22 Lu mult(Lu a,Lu b) 23 { 24 Lu c; 25 for(int i=0;i<=9;i++) 26 for(int j=0;j<=9;j++) 27 { 28 c.mp[i][j]=0; 29 for(int k=0;k<=9;k++) 30 c.mp[i][j]+=(a.mp[i][k]*b.mp[k][j])%m; 31 c.mp[i][j]%=m; 32 } 33 return c; 34 } 35 Lu solve(int x) 36 { 37 if(x==1) 38 return L1; 39 if(x&1) 40 { 41 Lu q=solve(x-1); 42 return mult(q,L1); 43 } 44 else 45 { 46 Lu q=solve(x/2); 47 return mult(q,q); 48 } 49 } 50 int main() 51 { 52 while(scanf("%d%d",&k,&m)!=EOF) 53 { 54 for(int i=0;i<=9;i++) 55 scanf("%d",&a[i]); 56 if(k<10) 57 { 58 printf("%d\n",k%m); 59 continue; 60 } 61 init(); 62 Lu tem=solve(k-9); 63 int ans=0; 64 for(int i=0;i<=9;i++) 65 ans+=(tem.mp[0][i]*f[i])%m; 66 printf("%d\n",ans%m); 67 } 68 return 0; 69 }
标签:style repr 计算 lines cas math pre sample roc
原文地址:http://www.cnblogs.com/--ZHIYUAN/p/6087345.html