思路:因为Q、S、B操作总和不超过100,因此怎么暴力怎么写。。。。当然记忆化搜索还是要的
#include#include #include #include #include using namespace std;#define maxn 705const int lx[]={-1,0,1,0};const int ly[]={0,-1,0,1};int n,m;int a[maxn][maxn],f[maxn][maxn];bool can[maxn][maxn];char s[10];inline int read(){ int x=0;char ch=getchar(); for (;ch<'0'||ch>'9';ch=getchar()); for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; return x;}int dp(int x,int y){ if (!can[x][y]) return -n*n; if (f[x][y]) return f[x][y]; f[x][y]=1; for (int i=0;i<4;i++){ int nx=x+lx[i],ny=y+ly[i]; if (nx>0&&ny>0&&nx<=n&&ny<=n&&a[x][y]>a[nx][ny]) f[x][y]=max(f[x][y],dp(nx,ny)+1); } return f[x][y];}int main(){ n=read(); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) a[i][j]=read(); m=read();memset(can,1,sizeof(can)); while (m--){ scanf("%s",s+1); if (s[1]=='C'){int x=read(),y=read(),v=read();a[x][y]=v;} if (s[1]=='S'){ int a=read(),b=read(),c=read(),d=read(); for (int i=a;i<=c;i++) for (int j=b;j<=d;j++) can[i][j]=0; } if (s[1]=='B'){ int a=read(),b=read(),c=read(),d=read(); for (int i=a;i<=c;i++) for (int j=b;j<=d;j++) can[i][j]=1; } if (s[1]=='Q'){ int ans=0;memset(f,0,sizeof(f)); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) ans=max(ans,dp(i,j)); printf("%d\n",ans); } } return 0;}