矩陣模版(例題3070、3744)

struct matrix 
{
    double A[NMax][NMax];
    matrix operator*(const matrix & m)
    {
        matrix ret={0,0,0,0};
        for(int i=0;i<NMax;i++)
            for(int k=0;k<NMax;k++)
                if(A[i][k]>0.0)
                    for(int j=0;j<NMax;j++)
                        ret.A[i][j]+=A[i][k]*m.A[k][j];
        return ret;
    }
}def={1,0,0,1};
matrix pow(matrix a,int n)
{
    matrix tmp=a,ret=def;
    while(n!=0)
    {
        if((n&1)!=0) ret=ret*tmp;
        tmp=tmp*tmp;
        n>>=1;
    }
    return ret;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章