"Red virus" issue
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4742 Accepted Submission (s): 1985
The new virus found in the Problem Description medical field is known as the "Red virus" because of its spreading speed and the "Red virus" spread on the internet, and the study found that in a single strand of DNA of the virus and its variants, cytosine and cytosine were paired.
Now there is a string of n in length that satisfies the condition:
(1) The string consists only of a,b,c,d four letters;
(2) a appears even several times (also can not appear);
(3) c appears even several times (also can not appear);
Calculates the number of strings that satisfy a condition.
When n=2, all strings that meet the criteria have the following 6: BB,BD,DB,DD,AA,CC.
Since this data can be very large, you just give the last two digits.
Input the first line of each set of inputs is an integer t, which indicates the number of test instances, the following is the T row data, an integer N (1<=n<2^64) per line, and ends when t=0.
Outputs for each test instance, the last two bits of the output string, followed by a blank line after each set of output.
Sample Input41420113142460
Sample outputcase 1:2case 2:72case 3:32case 4:0case 1:56case 2:72case 3:56
AuthorrabbitTransfer equation:
F[I][1] = 2 * f[i-1][1] + f[i-1][2] + f[i-1][3];
F[I][2] = f[i-1][1] + 2 * f[i-1][2] + f[i-1][4];
F[I][3] = f[i-1][1] + 2 * f[i-1][3] + f[i-1][4];
F[I][4] = f[i-1][2] + f[i-1][3] + 2 * f[i-1][4];
DP, relational matrix with matrix fast Power optimization:
2 1 1 0
1 2 0 1
1 0 2 1
0 1 1 2
Code:
1#include <iostream>2#include <cstring>3#include <string>4#include <cstdio>5#include <cmath>6 7 using namespacestd;8 9 #defineMOD 100Ten #defineMAXN 5 One AtypedefstructMAT - { - __int64 D[MAXN][MAXN]; the intR, C; - MAT () - { -r = c =0; +memset (D,0,sizeof(d)); - } + }mat; A atMat Mul (Mat M1, Mat m2,intMoD) - { -MAT ans =MAT (); -ANS.R =M1.R; -ANS.C =m2.c; - for(inti =0; i < M1.R; i++) in { - for(intj =0; J < M2.R; J + +) to { + if(M1.d[i][j]) - { the for(intK =0; K < m2.c; k++) * { $Ans.d[i][k] = (Ans.d[i][k] + m1.d[i][j] * m2.d[j][k])%MoD;Panax Notoginseng } - } the } + } A returnans; the } + -Mat Quickmul (Mat m, __int64 N,intMoD) $ { $MAT ans =MAT (); - for(inti =0; i < M.R; i++) - { theAns.d[i][i] =1; - }WuyiANS.R =M.R; theANS.C =m.c; - while(n) Wu { - if(N &1) About { $Ans =Mul (M, ans, MoD); - } -m =Mul (M, M, MoD); -N >>=1; A } + returnans; the } - $ intMain () { the intT; the while(SCANF ("%d", &t)! = EOF &&T) { the __int64 N; the for(inti =1; I <= T; i++) { -scanf"%i64d", &n); inMAT A =MAT (); theA.R =4, A.C =4; thea.d[0][0] =2; a.d[0][1] =1; a.d[0][2] =1; a.d[0][3] =0; Abouta.d[1][0] =1; a.d[1][1] =2; a.d[1][2] =0; a.d[1][3] =1; thea.d[2][0] =1; a.d[2][1] =0; a.d[2][2] =2; a.d[2][3] =1; thea.d[3][0] =0; a.d[3][1] =1; a.d[3][2] =1; a.d[3][3] =2; theA =Quickmul (A, N, MOD); +printf"Case %d:%d\n", I, a.d[0][0]); - } theprintf"\ n");Bayi } the}View Code
[HDOJ2065] "Red virus" issue