Matrix Fast Power 3 k*n grid

Source: Internet
Author: User

1#include <iostream>2#include <cstdlib>3#include <cstring>4#include <queue>5#include <cstdio>6#include <algorithm>7#include <map>8#include <time.h>9#include <ext/pb_ds/assoc_container.hpp>Ten#include <ext/pb_ds/tree_policy.hpp> One #defineLL Long Long A  - using namespacestd; - using namespace__gnu_pbds; the  -  - Const intMOD =12357; -  + structMartix - { +LL martix[260][260]; A     intRow,col; atMartix (int_row,int_col) -     { -memset (Martix,0,sizeof(Martix)); -row =_row; -Col =_col; -     } in     voidSets (int_row,int_col) -     { tomemset (Martix,0,sizeof(Martix)); +row =_row; -Col =_col; the     } *Martixoperator*(ConstMartix &a)Const $     {Panax Notoginseng Martix C (row, a.col); -          for(inti =0; i < row; i++) the              for(intj =0; J < A.col; J + +) +                  for(intK =0; K < Col; k++) A                 { theC.MARTIX[I][J] = (C.martix[i][j] + martix[i][k] *a.martix[k][j]); +                     if(C.martix[i][j] >=MOD) -c.martix[i][j]%=MOD; $                 } $  -         returnC; -     } the }; - Wuyi // the //line I do not place: new_x = x << 1, new_y = (y << 1) + 1; Number of columns +1 - //line I vertical dominoes: new_x = (x << 1) + 1, new_y = y << 1; Number of columns +1 Wu //line I horizontal dominoes: New x = (x << 2) + 3, new_y = (y << 2) + 3; Number of columns +2 -  About intK; $Martix A (260,260), F (260,260); - voidDfsintXintYintCol) - { -     if(col = = k) {A.martix[y][x] =1;return ;} ADFS (x<<1, (y<<1) +1, col+1); +DFS ((x<<1) +1, y <<1, col +1); the     if(col +2<=k) -DFS ((x <<2)+3, (Y <<2)+3, col+2); $ } the  the voidSolve () the { the     intN; -scanf"%d%d",&k,&n); in     if((k&1) && (n&1) ) the     { theprintf"%d\n",0); About         return ; the     } theA.sets (1<<k,1<<k); theF.sets (1<<k,1<<k); +Dfs0,0,0); -      for(inti =0; I < (1&LT;&LT;K); i++) theF.martix[i][i] =1;Bayi      while(N >0) the     { the         if(N &1) -F = f*A; -A = A *A; theN >>=1; the     } theprintf"%lld\n", f.martix[(1&LT;&LT;K)-1][ (1&LT;&LT;K)-1 ]); the } -  the intMainvoid) the { the solve ();94     return 0; the}

Matrix Fast Power 3 k*n grid

Contact Us

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.