• bzoj4887: [Tjoi2017]可乐


    一眼暴力宽搜(最近比赛想暴力想疯了。。。

    很明显的矩乘,然后自爆可以看作走向向一个无出边的点

    然后没啥难的了吧。

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    using namespace std;
    const int mod=2017;
    
    int n,m;
    struct Matrix
    {
        int mp[50][50];
        void clean(){memset(mp,0,sizeof(mp));}
        friend Matrix operator *(Matrix A,Matrix B)
        {
            Matrix C;C.clean();
            for(int i=1;i<=n+1;i++)
                for(int j=1;j<=n+1;j++)
                    for(int k=1;k<=n+1;k++)
                        C.mp[i][j]=(C.mp[i][j]+(A.mp[i][k]*B.mp[k][j])%mod)%mod;
            return C;
        }
    }A,ans;
    int main()
    {
        scanf("%d%d",&n,&m);
        A.clean();
        for(int i=1;i<=n;i++)A.mp[i][i]=1;
        for(int i=1;i<=n+1;i++)A.mp[i][n+1]=1;
        for(int i=1;i<=m;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            A.mp[x][y]=1;A.mp[y][x]=1;
        }
        
        ans.clean();ans.mp[1][1]=1;
        int p;
        scanf("%d",&p);
        while(p>0)
        {
            if(p%2==1)ans=ans*A;
            A=A*A;p/=2;
        }
        int sum=0;
        for(int i=1;i<=n+1;i++)
            for(int j=1;j<=n+1;j++)
                sum=(sum+ans.mp[i][j])%mod;
        printf("%d
    ",sum);
        return 0;
    }
  • 相关阅读:
    Run Shell Commands in Python
    Install Fabric 1.8.3 Manually on Ubuntu 12.04
    Setup a Simple HTTP Proxy Server
    去掉文件中的^M
    Build Web Server with Apache and Passenger
    Delete Trailing Spaces with Vim
    Specify Default JDK on Ubuntu
    总结
    问题
    HTTPS 和 HTTP
  • 原文地址:https://www.cnblogs.com/AKCqhzdy/p/8858294.html
Copyright © 2020-2023  润新知