当前位置:网站首页>(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;
}
边栏推荐
- [untitled]
- 现在券商的优惠开户政策是什么?现在在线开户安全么?
- 11 cnn简介
- 人人都当科学家之免Gas体验mint爱死机
- AUTO sharding policy will apply DATA sharding policy as it failed to apply FILE sharding policy
- NFT Platform Security Guide (2)
- HW safety response
- JVM notes
- [applet practice series] Introduction to the registration life cycle of the applet framework page
- 音视频学习(一)——PTZ控制原理
猜你喜欢

HW safety response

(1) Keras handwritten numeral recognition and recognition of self written numbers

人人都当科学家之免Gas体验mint爱死机

Development, deployment and online process of NFT project (2)

Analyse panoramique de la chaîne industrielle en amont, en aval et en aval de la NFT « Dry goods»

nanoPi Duo2连接wifi

还存在过有键盘的kindle?

Binding method of multiple sub control signal slots under QT

手写数字体识别,用保存的模型跑自己的图片

JS creative icon navigation menu switch background color
随机推荐
HW安全响应
svg野人动画代码
【leetcode】701. 二叉搜索树中的插入操作
feil_ The working directory on the left of uvission4 disappears
[file] VFS four structs: file, dentry, inode and super_ What is a block? difference? Relationship-- Editing
人人都当科学家之免Gas体验mint爱死机
7 user defined loss function
2 三种建模方式
现在券商的优惠开户政策是什么?现在在线开户安全么?
Common properties of XOR and addition
(一)keras手写数字体识别并识别自己写的数字
音视频学习(一)——PTZ控制原理
Audio and video learning (II) -- frame rate, code stream and resolution
TweenMax+SVG切换颜色动画场景
音视频学习(三)——sip协议
我想知道如何通过线上股票开户?在线开户安全么?
4 custom model training
H5 close the current page, including wechat browser (with source code)
面试踩坑总结一
[CEPH] Introduction to cephfs caps