1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| #include<bits/stdc++.h> using namespace std; const int max_n=1000006,mod=1000000007; inline int read(){ int x=0;bool w=0;char c=getchar(); while(c<'0' || c>'9') w|=c=='-',c=getchar(); while(c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return w?-x:x; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10^48); }
int n,m,p,ans; bool cant[max_n][8];
inline bool Can(int x,int y){ if(abs(x-y)>p) return 0; return cant[x][x-y+3]^1; }
int a[max_n],f[max_n][2][8];
inline int State(int can1,int can2,int can3){ return can1|(can2<<1)|(can3<<2); }
inline void ZhuanYi(int i,int j,int k){ bool can1=k&1,can2=(k>>1)&1,can3=(k>>2)&1; if(i>2){ if(!j){ if(can1 && ((can3 && Can(i,i+2) && Can(i+2,i-1)) || (!can3 && Can(i+2,i-1)))) f[i-1][j][State(can2,0,1)]=(f[i-1][j][State(can2,0,1)]+f[i][j][k])%mod; if(can2 && (!can1 || Can(i+2,i+1)) && (!can3 || Can(i,i+2))) f[i-1][j^1][State(0,1,1)]=(f[i-1][j^1][State(0,1,1)]+f[i][j][k])%mod; if(can3 && (!can1 || Can(i+2,i+1)) && Can(i-1,i+2)) f[i-1][j][State(can2,1,0)]=(f[i-1][j][State(can2,1,0)]+f[i][j][k])%mod; } else{ if(can1 && ((can3 && Can(i+2,i) && Can(i-1,i+2)) || (!can3 && Can(i-1,i+2)))) f[i-1][j][State(can2,0,1)]=(f[i-1][j][State(can2,0,1)]+f[i][j][k])%mod; if(can2 && (!can1 || Can(i+1,i+2)) && (!can3 || Can(i+2,i))) f[i-1][j^1][State(0,1,1)]=(f[i-1][j^1][State(0,1,1)]+f[i][j][k])%mod; if(can3 && (!can1 || Can(i+1,i+2)) && Can(i+2,i-1)) f[i-1][j][State(can2,1,0)]=(f[i-1][j][State(can2,1,0)]+f[i][j][k])%mod; } return; } if(!j){ if(can1 && (!can2 || Can(i+1,i)) && (!can3 || Can(i,i+2)) && Can(i+2,i-1) && Can(i-1,i+1)) ans=(ans+f[i][j][k])%mod; if(can2 && (!can1 || Can(i+2,i+1)) && (!can3 || Can(i,i+2)) && Can(i+1,i-1) && Can(i-1,i)) ans=(ans+f[i][j][k])%mod; if(can3 && (!can1 || Can(i+2,i+1)) && (!can2 || Can(i+1,i)) && Can(i,i-1) && Can(i-1,i+2)) ans=(ans+f[i][j][k])%mod; } else{ if(can1 && (!can2 || Can(i,i+1)) && (!can3 || Can(i+2,i)) && Can(i-1,i+2) && Can(i+1,i-1)) ans=(ans+f[i][j][k])%mod; if(can2 && (!can1 || Can(i+1,i+2)) && (!can3 || Can(i+2,i)) && Can(i-1,i+1) && Can(i,i-1)) ans=(ans+f[i][j][k])%mod; if(can3 && (!can1 || Can(i+1,i+2)) && (!can2 || Can(i,i+1)) && Can(i-1,i) && Can(i+2,i-1)) ans=(ans+f[i][j][k])%mod; } }
inline void Solve(){ f[n-2][0][7]=f[n-2][1][7]=1; for(register int i=n-2;i>1;--i) for(register int j=0;j<2;++j) for(register int k=0;k<8;++k) if(f[i][j][k]) ZhuanYi(i,j,k); write(ans); }
signed main(){ n=read(),m=read(),p=read(); if(n==1){ puts("1"); return 0; } if(n==2){ puts(m==0?"1":"0"); return 0; } if(p<2){ puts("0"); return 0; } for(register int i=1;i<=m;++i){ int x=read(),y=read(); if(abs(x-y)>p) continue; cant[x][x-y+3]=1; } if(p==2){ for(register int i=1;i<=n;++i){ if(i&1) a[i/2+1]=n-i; else a[n-i/2+1]=n-i; } ans=2,a[0]=a[n],a[n+1]=a[1]; for(register int i=1;i<=n;++i) if(!Can(a[i],a[i+1])){ --ans; break; } for(register int i=1;i<=n;++i) if(!Can(a[i],a[i-1])){ --ans; break; } write(ans); return 0; } Solve(); return 0; }
|