• [BZOJ1297][SCOI2009]迷路


    被卡了两个小时,发现是自己对这个东西没有理解透,是要让边数一一对应而不是点数一一对应,去掉一个+1后就过了,惨啊.

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<string>
    #include<cmath>
    #include<ctime>
    #include<algorithm>
    #include<map>
    #include<set>
    #include<queue>
    #include<iomanip>
    using namespace std;
    #define ll long long
    #define db double 
    #define up(i,j,n) for(int i=j;i<=n;i++)
    #define pii pair<int,int>
    #define uint unsigned int
    #define FILE "dealing"
    #define eps 1e-4
    int read(){
    	int x=0,f=1,ch=getchar();
    	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    	return x*f;
    }
    template<class T> bool cmax(T& a,T b){return a<b?a=b,true:false;}
    template<class T> bool cmin(T& a,T b){return a>b?a=b,true:false;}
    const int maxn=110,limit=50100,inf=1000000000,r=3,mod=2009;
    int N=100;
    struct Matrix{
    	int a[maxn][maxn];
    	void print(){
    		up(i,1,N){
    			up(j,1,N)printf("%d ",a[i][j]);
    			cout<<endl;
    		}
    		cout<<endl;
    	}
    	Matrix(){memset(a,0,sizeof(a));}
    	Matrix operator*(const Matrix& b){
    		memset(c,0,sizeof(c));
    		up(i,1,N)up(j,1,N)up(k,1,N)c.a[i][j]=(c.a[i][j]+a[k][j]*b.a[i][k])%mod;
    		return c;
    	}
    }b,a,ans,c;
    int main(){
    	freopen(FILE".in","r",stdin);
    	freopen(FILE".out","w",stdout);
    	int T,n;
    	n=read();T=read();
    	char ch;
    	up(i,1,n)up(j,1,8){
    			b.a[(i-1)*9+j][(i-1)*9+j+1]++;
    	}
    	up(i,1,n){
    		up(j,1,n){
    			scanf(" %c",&ch);
    			if(ch=='0')continue;ch-='0';
    			b.a[(i-1)*9+ch][(j-1)*9+1]++;
    		}
    	}
    	up(i,1,N)ans.a[i][i]=1;
    	for(;T;T>>=1,b=b*b)
    		if(T&1)ans=ans*b;
    	printf("%d
    ",ans.a[1][(n-1)*9+1]);
    	return 0;
    }
    

      

  • 相关阅读:
    【Python】错误、调试和测试
    【c++ primer, 5e】函数指针
    【英语学习】【17/4/1】
    【c++ primer, 5e】函数匹配
    FIRST GAME.
    【Thinking in Java, 4e】访问权限控制
    【c++ primer, 5e】特殊用途语言特性
    Top-Down笔记 #01# 计算机网络概述
    NHibernate之映射文件配置说明
    Web Service 部署到IIS服务器
  • 原文地址:https://www.cnblogs.com/chadinblog/p/6560396.html
Copyright © 2020-2023  润新知