当前位置:网站首页>Grid division [DFS]
Grid division [DFS]
2022-04-21 08:43:00 【Sss_ xxh、】
Topic
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , Failed to save the picture , The origin station may have anti-theft chain mechanism , It is recommended to save the picture and upload it directly (imGO6YD2fvEZ-1650374146304)(%E6%96%B9%E6%A0%BC%E5%88%86%E5%89%B2.assets/image-2022041921111 Cut road 3192)(%E6%96%B9%E6%A0%BC%E5%88%86%E5%89%B2.assets/image-20220419211118498.png)]](/img/39/1929a57b7305a49292ef3972afa8a3.png)
Ideas
dfs Split the path
Because as like as two peas, two figures are split. , So the path must pass (3, 3) This point , And the paths on both sides must be symmetrical .
So, from (3, 3) Start dfs, Mark the current point it has passed as passed , Then mark the other symmetrical side as passing through , So you can go on both sides at the same time .
Once you get to the boundary, the answer is +1
The final answer needs to be divided by 4, Because the two parts of symmetry will repeat .
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int g[N][N];
int ans = 0;
int xx[4] = {
0, 1, 0, -1};
int yy[4] = {
1, 0, -1, 0};
void dfs(int x, int y)
{
g[x][y] = 1;
if (x == 0 || x == 6 || y == 0 || y == 6)
{
ans ++;
return;
}
for (int i = 0; i < 4; i ++ )
{
int dx = x + xx[i];
int dy = y + yy[i];
if (dx >= 0 && dx <= 6 && dy >= 0 && dy <= 6 && g[dx][dy] == 0)
{
g[dx][dy] = 1;
g[6 - dx][6 - dy] = 1;
dfs(dx, dy);
g[dx][dy] = 0;
g[6 - dx][6 - dy] = 0;
}
}
}
int main()
{
/* code */
dfs(3, 3);
cout << ans/4 << endl;
return 0;
}
版权声明
本文为[Sss_ xxh、]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210839149732.html
边栏推荐
猜你喜欢

多线程小抄集(新编二)

2、 Wechat applet - Quick Review (page file)

【Appium】使用模拟器实现有道云App的业务功能-新增、搜索、修改、删除
![[arm assembly judgment] how to use assembly to judge the number of positive and negative numbers in an array?](/img/96/de72a6446ff1405697ff90369946ed.png)
[arm assembly judgment] how to use assembly to judge the number of positive and negative numbers in an array?

Flink的api入门案例

Leetcode0824. 山羊拉丁文(simple,字符串处理)

You can remove cached packages by executing ‘yum clean packages‘. Error: GPG check FAILED

归一标准化后knn鸢尾花种类预测

Ghost blank node properties

You can remove cached packages by executing ‘yum clean packages‘. Error: GPG check FAILED
随机推荐
Signalr console as server
Taobao applet experience Optimization: data analysis and Optimization Practice
Zabbix 5.4 Server安装
Workerman给Timer定时器里的方法传参数
多线程小抄集(新编二)
Be sure to watch the nine steps of MES selection, which is worth collecting and watching repeatedly (Part 2)
Insert a new node before the linked list node
signalr 控制台做服务端
Configure multiple SSH keys
2022茶艺师(初级)考题及在线模拟考试
7.4 parallel convolutional neural network googlenet
数据集划分小探
加入log4j日志功能
渗透实战-挖掘某学校站点漏洞(APP漏洞)
36氪首发|「甄知科技」收购数智化开发平台「猪齿鱼」,将和已有产品「燕千云」融合形成产品闭环
JVM——》常用参数
Analysis of VoIP technology of network telephone
Various database connection strings (efcore)
uniapp 热更新和整包更新
C语言计数排序