1. 程式人生 > >BZOJ3208花神的秒題計劃

BZOJ3208花神的秒題計劃

記憶化搜尋

暴力模擬即可

每次保護或撤銷或改變海拔就暴力修改,然後對於詢問,記憶化搜尋一下就好了

程式碼

//By AcerMo
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1050;
int n,m;
int a[M][M],f[M][M],vis[M][M];
int fx[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
inline
void read(int &x) { x=0;char ch=getchar(); while (!isdigit(ch)) ch=getchar(); while (isdigit(ch)) x=x*10+ch-'0',ch=getchar(); return ; } inline void flag(int x,int y,int z,int g,bool f) { for (int i=x;i<=z;i++) for (int k=y;k<=g;k++) vis[i][k]=f; return ; } inline int find(int x,int y)
{ if (vis[x][y]) return -2e9; if (f[x][y]!=-1) return f[x][y]; f[x][y]=1; for (int i=0;i<4;i++) { int nx=x+fx[i][0]; int ny=y+fx[i][1]; if (nx<1||nx>n||ny<1||ny>n) continue; if (a[x][y]>a[nx][ny]) f[x][y]=max(f[x][y],find(nx,ny)+1); } return f[x][y]; } signed main(
) { read(n); for (int i=1;i<=n;i++) for (int k=1;k<=n;k++) read(a[i][k]); read(m);int x,y,z,g; while (m--) { char c;cin>>c; if (c=='Q') { memset(f,-1,sizeof(f)); int ans=0; for (int i=1;i<=n;i++) for (int k=1;k<=n;k++) ans=max(ans,find(i,k)); printf("%d\n",ans); continue; } read(x),read(y),read(z); if (c=='C'){a[x][y]=z;continue;} read(g); if (c=='B') flag(x,y,z,g,0); if (c=='S') flag(x,y,z,g,1); } return 0; }