zoukankan      html  css  js  c++  java
  • [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;
    }
    

      

  • 相关阅读:
    在Centos 7下编译openwrt+njit-client
    开博随笔
    Chapter 6. Statements
    Chapter 4. Arrays and Pointers
    Chapter 3. Library Types
    Chapter 2.  Variables and Basic Types
    关于stm32不常用的中断,如何添加, 比如timer10 timer11等
    keil 报错 expected an identifier
    案例分析 串口的地不要接到电源上 会烧掉
    案例分析 CAN OPEN 调试记录 进度
  • 原文地址:https://www.cnblogs.com/chadinblog/p/6560396.html
Copyright © 2011-2022 走看看