CodeForces 593E
2016-11-29 13:54
204 查看
按时间分段,
在每个时间段内,进行矩阵快速幂
在每个时间段内,进行矩阵快速幂
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int mod=1000000007; int M[44][44],Me[44][44],V[44],Ve[44],n; void pow_M(int e){ while(1) { if(e&1) { memset(Ve,0,sizeof(Ve)); for(int i=0;i<n;i++)for(int j=0;j<n;j++) Ve[i]=(Ve[i]+M[j][i]*(long long)V[j])%mod; for(int i=0;i<n;i++)V[i]=Ve[i]; } e>>=1; if(e==0)break; memset(Me,0,sizeof(Me)); for(int i=0;i<n;i++)for(int j=0;j<n;j++)for(int k=0;k<n;k++) Me[i][j]=(Me[i][j]+M[i][k]*(long long)M[k][j])%mod; for(int i=0;i<n;i++)for(int j=0;j<n;j++)M[i][j]=Me[i][j]; } } int C[44][44],x,y,q; void build() { for(int i=0;i<n;i++)for(int j=0;j<n;j++) { int a=i/y,b=i%y; int A=j/y,B=j%y; int k=abs(A-a)+abs(B-b); if(k<=1&&C[a][b]==0&&C[A][B]==0)M[i][j]=1; else M[i][j]=0; } } int main() { #ifdef DouBi freopen("input.cpp","r",stdin); #endif // DouBi while(scanf("%d%d%d",&x,&y,&q)!=EOF){ n=x*y; int t=1; memset(V,0,sizeof(V));V[0]=1; memset(C,0,sizeof(C)); while(q--) { build(); int l,a,b,k;scanf("%d%d%d%d",&l,&a,&b,&k);--a;--b; pow_M(k-t); t=k; if(l==3){V[a*y+b]=0;C[a][b]=0;} if(l==2){V[a*y+b]=0;C[a][b]=1;} if(l==1)printf("%d\n",V[a*y+b]); } //printf("line\n"); } return 0; }
相关文章推荐
- codeforces 593E(矩阵类题目)
- codeforces 593E
- codeforces----193A Cutting Figure
- codeforces 510B Fox And Two Dots(dfs)
- CodeForces 651A:Joysticks【模拟】
- CodeForces 446A DZY Loves Sequences
- Codeforces 437C The Child And Toy 贪心
- CodeForces - 763A Timofey and a tree (树性质的应用)
- Codeforces 650E Clockwork Bomb 并查集+set
- CodeForces 16C Monitor(gcd,水题)
- codeforces 225C Barcode
- Codeforces 599C Day at the Beach
- 【codeforces】Bear and Three Balls
- codeforces - 782B - The Meeting Place Cannot Be Changed
- CodeForces 789B (Masha and geometric depression)
- Codeforces 939D Love Rescue(并查集)
- Codeforces Round #118 (Div. 2) B题(Codeforces上不支持qsort,只支持sort!!!)
- Codeforces 484D. Kindergarten DP贪心
- Codeforces 633H. Fibonacci-ish II (Mo's Algorithm(莫队算法) + 线段树 + 离散化)
- codeforces 710C Magic Odd Square