bzoj2973: 石头游戏

你还要作死吗余梓灏,垃圾

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;

int n,m,ti;
char sc[10][10],ss[12][12];int sslen[12];
struct Matrix
{
    LL mp[110][110];
    Matrix(){}
    Matrix friend operator *(Matrix a,Matrix b)
    {
        Matrix c;
        memset(c.mp,0,sizeof(c.mp));
        for(int i=1;i<=n*m+1;i++)
            for(int j=1;j<=n*m+1;j++)
                for(int k=1;k<=n*m+1;k++)
                    c.mp[i][j]+=a.mp[i][k]*b.mp[k][j];
        return c;
    }
    void clean(){memset(mp,0,sizeof(mp));}
    void init()
    {
        memset(mp,0,sizeof(mp));
        for(int i=1;i<=n*m+1;i++)mp[i][i]=1;
    }
}ans,rst,now,al;

int main()
{
//    freopen("1.out","w",stdout);
    int act;
    scanf("%d%d%d%d",&n,&m,&ti,&act);
    for(int i=1;i<=n;i++)scanf("%s",sc[i]+1);
    for(int i=1;i<=act;i++){scanf("%s",ss[i]+1);sslen[i]=strlen(ss[i]+1);}
    
    int Rest=ti%60;
    rst.init();al.init();
    for(int t=1;t<=60;t++)
    {
        now.init();
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            {
                int id=sc[i][j]-'0'+1;
                char ch=ss[id][(t-1)%sslen[id]+1];
                
                int p=(i-1)*m+j;
                if('0'<=ch&&ch<='9')now.mp[n*m+1][p]=ch-'0';
                else
                {
                    now.mp[p][p]=0;
                         if(ch=='N'&&i-1>=1)now.mp[p][p-m]=1;
                    else if(ch=='W'&&j-1>=1)now.mp[p][p-1]=1;
                    else if(ch=='S'&&i+1<=n)now.mp[p][p+m]=1;
                    else if(ch=='E'&&j+1<=m)now.mp[p][p+1]=1;
                }
            }
        
        //------get now-------------
        
        al=al*now;
        if(Rest>0) rst=rst*now, Rest--;
/*    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            printf("%lld ",ans.mp[1][(i-1)*m+j]);
        printf("\n");
    }
    printf("\n");*/
    }
    ti/=60;ans.clean();ans.mp[1][n*m+1]=1;
    while(ti!=0)
    {
        if(ti%2==1)ans=ans*al;
        al=al*al;ti/=2;
    }
    ans=ans*rst;
    
        LL mmax=0;
    for(int i=1;i<=n*m;i++)mmax=max(mmax,ans.mp[1][i]);
    printf("%lld\n",mmax);
    return 0;
}

 

posted @ 2018-07-20 10:08  AKCqhzdy  阅读(340)  评论(0编辑  收藏  举报