[Explanations] luogu_P4159_ lost (matrix floyd

:( for a long time did not write the foreword) Apple actually released in 9102 18W fast charge finally caught up with the level of domestic thousand Yuan machine! Industry conscience ah! A mere 243 yuan to buy as long as the charger! Buy up to 2m long line of charge as long as the increase 272 yuan on it! I think the price is how to do it is used in the new iPhone pro stunning new design was actually three gas stove than 2080ti even more than a hole 1200w pixel camera no longer join a 200w pixel camera consisting of four sold more than one thousand photo more conscience of the industry is actually waiting for next year squeezing toothpaste (above actually comes from the aesthetics of science and technology

Read Borderlands 3 media demo though I am a witch lover but I chose Zane


 

The question has long been talked about, it is still very good

If we know the number of edge weights only 1 and 0 can be quickly calculated power with floyd and matrix schemes

But here the right side of 1 to 9, in fact, very small

So we can point split into nine points, between the right edge of 1, a point to this point right side for the first few points and even a few on the side of this point, so that you can floyd the

#include<bits/stdc++.h>

using namespace std;
const int maxn=109;
const int mod=2009;
int n,m,t;
struct node{
    int a[maxn][maxn];
    node(){}
    void clear(){
        memset(a,0,sizeof(a));
    }
    node operator *(const node &t)const{
        node ans;ans.clear();
        for(int i=1;i<=m;i++)
        for(int j=1;j<=m;j++)
        for(int k=1;k<=m;k++)
        ans.a[i][j]=(ans.a[i][j]+a[i][k]*t.a[k][j])%mod;
        return ans;
    }
}f;
node operator ^(node a,int b){
    node ans;ans.clear();
    for(int i=1;i<=m;i++)ans.a[i][i]=1;
    while(b){
        if(b&1)ans=ans*a;
        a=a*a;
        b>>=1;
    }
    return ans;
}
char s[maxn][maxn];
int hsh(int x,int y){
    return x+y*n;
}
int main(){
    scanf("%d%d",&n,&t);m=n*9;
    for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=8;j++)
        f.a[hsh(i,j)][hsh(i,j-1)]=1;
        for(int j=1;j<=n;j++)
        f.a[i][j+(s[i][j]-'0'-1)*n]=1;
    }
    f=f^t;
    printf("%d\n",f.a[1][n]);
}

 

Guess you like

Origin www.cnblogs.com/superminivan/p/11504448.html