记忆化搜索

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std; typedef long long LL; #define INF 0x7fffffff
#define N 710 int n,m;
int aa,bb,cc,dd; int xx[4]={0,0,1,-1},
yy[4]={1,-1,0,0}; int a[N][N],f[N][N]; char ch[2]; bool v[N][N];
int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void change(int x,int y,int val)
{
a[x][y]=val;
} void mark(int aa,int bb,int cc,int dd,bool f)
{
for (int i=aa;i<=bb;i++)
for (int j=cc;j<=dd;j++)
v[i][j]=f;
} int dfs(int x,int y)
{
if (v[x][y])
return -INF;
if (f[x][y]!=-1)
return f[x][y];
f[x][y]=1;
for (int i=0;i<4;i++)
{
int tx=x+xx[i],
ty=y+yy[i];
if (tx<1 || ty<1 || tx>n || ty>n)
continue;
if (a[x][y]>a[tx][ty])
f[x][y]=max(f[x][y],dfs(tx,ty)+1);
}
return f[x][y];
} int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
scanf("%d",&a[i][j]);
scanf("%d",&m);
while (m--)
{
scanf("%s",ch);
if (ch[0]=='C')
{
scanf("%d%d%d",&aa,&bb,&cc);
change(aa,bb,cc);
}
if (ch[0]=='S')
{
scanf("%d%d%d%d",&aa,&cc,&bb,&dd);
mark(aa,bb,cc,dd,1);
}
if (ch[0]=='B')
{
scanf("%d%d%d%d",&aa,&cc,&bb,&dd);
mark(aa,bb,cc,dd,0);
}
if (ch[0]=='Q')
{
int maxn=0;
memset(f,-1,sizeof(f));
for (int j=1;j<=n;j++)
for (int k=1;k<=n;k++)
maxn=max(maxn,dfs(j,k));
printf("%d\n",maxn);
}
}
return 0;
}

  

最新文章

  1. iOS UIAlertController跟AlertView用法一样 &amp;&amp; otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法
  2. CoreData基础
  3. Asp.net Mvc模块化开发系列(目录)
  4. oracle 用户锁定及到期
  5. 安装Android SDK和ADT步骤和遇到的问题
  6. 代码开光,Orz
  7. Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)
  8. JSON 数据的系统解析
  9. 高级UNIX环境编程10 信号
  10. App 组件化/模块化之路——构建开发架构思路
  11. Android程序崩溃异常收集框架
  12. UNIX环境高级编程——IPC总结
  13. Windows 10安装Docker 步骤及顺序
  14. JMeter已传值但是提示为空
  15. Linux hostname设置,静态ip设置,hostname与静态ip相互映射
  16. Cortex-M3 跳转到指定bin执行
  17. vscode使用wsl调试代码
  18. django中使用mysql数据库的事务
  19. SpringBoot实用技巧札记
  20. win10下安装redis 服务

热门文章

  1. swiper实现响应式全屏自动轮播
  2. 启用Windows10的Linux子系统并安装图形界面
  3. buf.entries()详解
  4. Springboot开启事务
  5. java读utf8 的txt文件,第一个字符为空或问号问题
  6. parse XML &amp; js
  7. [luoguP2401] 不等数列
  8. HDU 4948 (傻比图论)
  9. MTK平台释疑android M 配置中断相关问题
  10. iphone原生cookie处理