HDU1575(矩阵快速幂模板题)

简单的矩阵快速幂,输入矩阵直接套模板做就行了。
code

#include
#include
#include
#include
#include
#include
#include 
#include
//a&3==a%4
using namespace std ;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const double eps = 1e-8;
const int maxn = 110010;
const int inf = 0x3f3f3f3f;
const ll mod=9973ll;

struct matrix
{
    ll mat[10][10];//mat[i][j]=µÚiÐеÚjÁÐ
    matrix()
    {
        for(int i=0;i<10;i++)
        {
            for(int j=0;j<10;j++)
            {
                mat[i][j]=0ll;
            }
        }
    }
};

void out(matrix a,int n)
{
    for(int i=0;ifor(int j=0;jcout<"   ";
        }
        cout<int n)
{
    matrix res;
    for(int i=0;ifor(int j=0;jfor(int k=0;kreturn res;
}

matrix quickmi(matrix a,ll b,int n)
{
    matrix E;
    matrix res;
    for(int i=0;i1;
        res.mat[i][i]=1;
    }
    E=multiply(a,E,n);
    while(b>0)
    {
        if(b%2==1)
        {
            res=multiply(res,E,n);
        }
        b=b/2;
        E=multiply(E,E,n);
    }
    return res;
}

int main()
{;
    int _case;
    scanf("%d",&_case);
    while(_case--)
    {
        int n;
        ll k;
        matrix sum;
        scanf("%d",&n);
        cin>>k;
        for(int i=0;ifor(int j=0;jcin>>a;
                sum.mat[i][j]=a;
            }
        }
        matrix res=quickmi(sum,k,n);
        ll sumres=0;
        for(int i=0;icout<return 0;
}

你可能感兴趣的:(hdu,数学,矩阵快速幂)