当前位置:网站首页>(DFS search) acwing 2005 horseshoe
(DFS search) acwing 2005 horseshoe
2022-06-26 15:58:00 【Honestbutter-】
DFS Explosive search
Key features of state transition :
(Can walk to(or)however)We can only go to), So the status of the last point should be recorded , So as to judge whether the current point can go- Update answers to meet
(The number of is equal to)The number of , Therefore, record the explosive search
#include<iostream>
#include<algorithm>
using namespace std;
const int N=10;
char g[N][N];
bool st[N][N];
int n,ans;
int dx[]={
0,1,0,-1},dy[]={
1,0,-1,0};
void dfs(int l,int r,int x,int y) //f:0( f:1)
{
st[x][y]=true; // Note that it is marked in this position st, Because the first point should also be marked
if(l==r)
{
ans=max(l+r,ans);
st[x][y]=false; // Don't forget to restore the scene
return;
}
for(int i=0;i<4;i++)
{
int a=x+dx[i],b=y+dy[i];
if(a<0||b<0||a>=n||b>=n||st[a][b]) continue;
if(g[a][b]=='('&&g[x][y]==')') continue;
if(g[a][b]==')') dfs(l,r+1,a,b);
else dfs(l+1,r,a,b);
}
st[x][y]=false;
}
int main()
{
cin>>n;
for(int i=0;i<n;i++) cin>>g[i];
if(g[0][0]=='(') dfs(1,0,0,0);
cout<<ans<<endl;
return 0;
}
边栏推荐
- NFT 平台安全指南(2)
- Nanopi duo2 connection WiFi
- Swiftui retrieves the missing list view animation
- 11 cnn简介
- Failed to get convolution algorithm. This is probably because cuDNN failed to initialize
- golang 1.18 go work 使用
- Solana扩容机制分析(1):牺牲可用性换取高效率的极端尝试 | CatcherVC Research
- JS creative icon navigation menu switch background color
- Audio and video learning (II) -- frame rate, code stream and resolution
- 2 three modeling methods
猜你喜欢

Everyone is a scientist free gas experience Mint love crash

还存在过有键盘的kindle?

Svg canvas canvas drag

El dialog drag and drop, the boundary problem is completely corrected, and the bug of the online version is fixed

NFT 项目的开发、部署、上线的流程(2)

STEPN 新手入门及进阶

svg canvas画布拖拽

Transformation of zero knowledge QAP problem

振动式液量检测装置

Stepn débutant et avancé
随机推荐
【leetcode】331. 验证二叉树的前序序列化
9 Tensorboard的使用
AUTO sharding policy will apply DATA sharding policy as it failed to apply FILE sharding policy
[graduation season · advanced technology Er] what is a wechat applet, which will help you open the door of the applet
canvas三个圆点闪烁动画
NFT交易原理分析(1)
Have you ever had a Kindle with a keyboard?
AbortController的使用
Development, deployment and online process of NFT project (2)
7 user defined loss function
Analyse panoramique de la chaîne industrielle en amont, en aval et en aval de la NFT « Dry goods»
Failed to get convolution algorithm. This is probably because cuDNN failed to initialize
Super double efficiency! Pycharm ten tips
面试踩坑总结一
SVG大写字母A动画js特效
svg上升的彩色气泡动画
Svg animation around the earth JS special effects
AUTO sharding policy will apply DATA sharding policy as it failed to apply FILE sharding policy
Selenium chrome disable JS disable pictures
Stepn débutant et avancé