【bzoj3208】花神的秒题计划Ⅰ
2024-08-22 22:56:22
记忆化搜索
#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;
}
最新文章
- iOS UIAlertController跟AlertView用法一样 &;&; otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法
- CoreData基础
- Asp.net Mvc模块化开发系列(目录)
- oracle 用户锁定及到期
- 安装Android SDK和ADT步骤和遇到的问题
- 代码开光,Orz
- Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)
- JSON 数据的系统解析
- 高级UNIX环境编程10 信号
- App 组件化/模块化之路——构建开发架构思路
- Android程序崩溃异常收集框架
- UNIX环境高级编程——IPC总结
- Windows 10安装Docker 步骤及顺序
- JMeter已传值但是提示为空
- Linux hostname设置,静态ip设置,hostname与静态ip相互映射
- Cortex-M3 跳转到指定bin执行
- vscode使用wsl调试代码
- django中使用mysql数据库的事务
- SpringBoot实用技巧札记
- win10下安装redis 服务