版本比较
做题心得 - 2025 NOIP #45 - T2
正文
增加 9 行删除 9 行
27 行未改动282930313232333435363737383940413 行未改动454647484949505152536 行未改动606162636464656667686970717172737475767777787979808182838484858687888989909192938 行未改动27 行未改动 hx[]={0,-1,-1,0,0,1,1,0}, hy[]={1,0,0,-1,-1,0,0,1};ll f[N][N][2][2];bool h[N][N],e[N][N];int n,m; int n,m;void dp(int i,int j,int x1,int x2,int x3,int x4,int x5,int x6,int x7,int x8){ f[i][j][0][0]=(f[i-1][j][0][0]*x1+f[i-1][j][1][0]*x5)%P; f[i][j][1][0]=(f[i-1][j][0][1]*x2+f[i-1][j][1][1]*x6)%P; f[i][j][0][1]=(f[i][j-1][0][0]*x3+f[i][j-1][1][0]*x7)%P; f[i][j][1][1]=(f[i][j-1][0][1]*x4+f[i][j-1][1][1]*x8)%P; f[i][j][1][1]=(f[i][j-1][0][1]*x4+f[i][j-1][1][1]*x8)%P;}int main(){ freopen("centrallimit.in","r",stdin); freopen("centrallimit.out","w",stdout);3 行未改动 cin>>n>>m; Rep(i,1,m){ int x,y; cin>>x>>y; h[x][y]=1; h[x][y]=1; } Rep(x,0,n)Rep(y,0,n)if(h[x][y])Rep(d,0,5){ int nx=x+dx[d],ny=y+dy[d]; if(nx<0||nx>n||ny<0||ny>n) continue;6 行未改动 if(!e[0][1]) f[0][1][0][1]=1; if(!e[1][0]) f[1][0][0][0]=1; if(!e[1][1]) f[1][1][1][0]=!e[0][1], f[1][1][0][1]=!e[1][0]; Rep(i,2,n) if(!e[i][0]) f[i][0][0][0]=f[i-1][0][0][0]; Rep(i,2,n) if(!e[i][0]) f[i][0][0][0]=f[i-1][0][0][0]; Rep(i,2,n) if(!e[0][i]) f[0][i][1][1]=(f[0][i-1][0][1]+f[0][i-1][1][1])%P; Rep(i,2,n) if(!e[i][1]){ // have/not have a horse f[i][1][0][0]=(f[i-1][1][1][0]+f[i-1][1][0][0]*(h[i-2][0]?h[i-1][0]:1))%P; f[i][1][1][0]=f[i-1][1][0][1]; f[i][1][0][1]=f[i][0][0][0]; } } Rep(i,2,n) if(!e[1][i]){ // have/not have a horse if(h[0][i-2]) f[1][i][1][1]=(f[1][i-1][0][1]+f[1][i-1][1][1]*h[0][i-1])%P; else f[1][i][1][1]=(f[1][i-1][1][1]+f[1][i-1][0][1])%P; f[1][i][0][1]=f[1][i-1][1][0]; f[1][i][1][0]=f[0][i][1][1]; f[1][i][1][0]=f[0][i][1][1]; } Rep(i,2,n)Rep(j,2,n){ Rep(i,2,n)Rep(j,2,n){ if(h[i-1][j-2]&&h[i-2][j-1]) continue; // too many horse if(e[i][j]) continue; // be eaten if(h[i-1][j-2]){ // horse leg broken if(h[i-1][j-1]) dp(i,j,1,0,0,1,1,1,1,1); if(h[i-1][j-1]) dp(i,j,1,0,0,1,1,1,1,1); else dp(i,j,0,0,0,1,0,1,1,0); }else if(h[i-2][j-1]){ // horse leg broken if(h[i-1][j-1]) dp(i,j,1,1,1,1,1,0,0,1); else dp(i,j,0,1,1,0,1,0,0,0); else dp(i,j,0,1,1,0,1,0,0,0); }else dp(i,j,1,1,1,1,1,1,1,1); } cout<<(8 行未改动