标签:wan limit mat java memset clu hdu its tput
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1221 Accepted Submission(s): 722
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int mod = 200907; 5 struct mat{ 6 ll m[3][3]; 7 mat(){ 8 memset(m, 0, sizeof(m)); 9 } 10 }; 11 12 mat mul(mat &A, mat &B) { 13 mat C; 14 for(int i = 0; i < 3; i ++) { 15 for(int j = 0; j < 3; j ++) { 16 for(int k = 0; k < 3; k ++) { 17 C.m[i][j] = (C.m[i][j] + A.m[i][k]*B.m[k][j]) % mod; 18 } 19 } 20 } 21 return C; 22 } 23 24 mat pow(mat A, int n) { 25 mat B; 26 for(int i = 0; i < 3; i ++) B.m[i][i] = 1; 27 while(n) { 28 if(n&1) B = mul(B, A); 29 A = mul(A, A); 30 n >>= 1; 31 } 32 return B; 33 } 34 int main() { 35 int n; 36 while(cin >> n, n) { 37 mat A; 38 A.m[0][0] = A.m[0][2] = A.m[1][0] = A.m[2][2] = 1; 39 A.m[0][1] = 2; 40 A = pow(A, n-1); 41 cout << (A.m[0][0]+A.m[0][2]) % mod << endl; 42 } 43 return 0; 44 }
标签:wan limit mat java memset clu hdu its tput
原文地址:https://www.cnblogs.com/xingkongyihao/p/9007387.html