# HDU 5434 Peace Small elephant-like pressure dp+ matrix fast power

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=5434

Peace Small Elephantaccepts:38submissions:108Time limit:10000/5000 MS (java/others)Memory limit:65536/65536 K (java/others)Problem description
Xiao Ming likes chess very much, especially like the elephant in chess (as long as no block can be inclined to walk any lattice), but he thought the chess elephant is too ferocious, so he thought of the little elephant, the elephant is not so ferocious, its attack range is its current lattice right angle diagonal pair of lattice. Now Xiao Ming wants to put a lot of small elephant on the board, interestingly, when the two small elephant lattice has a common side, they will fit into a composite image, a plurality of small elephant satisfies the condition will also be fitted, the attack range of the general elephant is also the lattice that it covers the right angle of the lattice area, now requires that any image of the attack range That is, Xiao Ming's chess board is very special, there arem*nm∗n lattice, to meet the conditions of the placement of the number of scenarios, because the number of programs is too large, need to 10000000071000000 007 modulo. The following shows the attack range of the image under several shapes, and the cross indicates the range of the attack.
Enter a description
Enter more than one set of data (up to55 groups) with two integers per set of dataNmn,m meaning as described in the topic. 1 \leq m \leq 7,1 \leq n \leq 10000000001≤m≤7,1≤n≤10 00000000
Output description
Each set of data corresponds to an output line that contains an integer representing the number of scenarios that meet the condition.
Input sample
1 12 3
Output sample
250
Exercises

The fast power of the dp+ matrix of the shape pressure.

For several days, and finally knocked out!

A detailed explanation, add tomorrow, sleep First >

Code:
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 Const intMAXN =155;7 Const intMoD =1000000007;8 9typedefLong LongLL;Ten  One structMatrix { A     intN, M; -     intVAL[MAXN][MAXN]; -Matrix (intNintm): N (N), M (m) {} the Matrix () {} -     voidInitintNintm) { This->n = n; This->m =m;} -Friend Matrixoperator* (Constmatrix& MAT1,Constmatrix&mat2) { - Matrix ret (MAT1.N, MAT2.M); +          for(inti =0; i < RET.N; i++) { -              for(intj =0; J < RET.M; J + +) { +RET.VAL[I][J] =0; A                  for(intK =0; K < mat1.m; k++) { atRET.VAL[I][J] + = (LL) mat1.val[i][k] * mat2.val[k][j]%MoD; -RET.VAL[I][J]%=MoD; -                 } -             } -         } -         returnret; in     } - }; to  + voidPower (matrix& Mat,intN, matrix&ans) { -      while(N >0) { the         if(n%2) ans = mat*ans; *Mat = mat*Mat; $N/=2;Panax Notoginseng } - } the + int_n, M; A the BOOLIsOk (intS1,intS2) { + for(inti =0; i<m; i++) { - if((s1& (1<< i) &&! (s2& (1<<i )) {$             intJ; $j = i-1; - if(J >=0) { - if((s2& (1<< j) &&! (s1& (1<< j)))return false; the } -j = i +1;Wuyi if(j<m) { the if((s2& (1<< j) &&! (s1& (1<< j)))return false; - } Wu } - } About return true;$ } -  - Matrix mat, ans; -  A voidinit () { +Mat.init (1<< m,1<<m); the      for(inti =0; i<mat.n; i++) { -          for(intj =0; j<mat.m; J + +) { \$             if(IsOk (I, J)) Mat.val[i][j] =1; the             ElseMAT.VAL[I][J] =0; the         } the     } the  -Ans.init (1<< m,1); in      for(inti =0; i < ANS.N; i++) ans.val[i][0] =1; the } the  About intMain () { the      while(SCANF ("%d%d", &_n, &m) = =2&&_n) { the init (); thePower (Mat, _n-1, ans); +         intres =0; -          for(inti =0; i < ANS.N; i++) { theRes + = ans.val[i][0];BayiRes%=MoD; the         } theprintf"%d\n", res); -     } -     return 0; the}
View Code

HDU 5434 Peace Small elephant-like pressure dp+ matrix fast power

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.