当前位置:网站首页>[蓝桥杯2017初赛]方格分割
[蓝桥杯2017初赛]方格分割
2022-07-06 09:14:00 【%xiao Q】
题目

分析
因为每种方案都是经过中间那个点(3,3),所以我们可以从(3,3)开始分2个方向 搜索(并且这2方向是对称的,所以当一个方向到边界,另一个也会到边界,也就是一种答案)
参考代码
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <unordered_map>
#define LL long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
#define pre(i, a, b) for(int i = b; i >= a; i--)
using namespace std;
typedef pair<int, int> PII;
bool st[10][10] = {
0};
int dx[] = {
1, -1, 0, 0};
int dy[] = {
0, 0, 1, -1};
int ans = 0;
void dfs(int x, int y)
{
// 遇到边界就是一种方案
if(x == 0 || x == 6 || y == 0 || y == 6)
{
ans++;
return ;
}
rep(i, 0, 3)
{
int x1 = x + dx[i], y1 = y + dy[i];
int x2 = 6 - x1, y2 = 6 - y1; //(X1,y1)关于(3,3)对称的点
if(x1 < 0 || x1 > 6 || y1 < 0 || y1 > 6 || st[x1][y1]) continue;
st[x1][y1] = st[x2][y2] = true; //2个对称的点同是标记
dfs(x1, y1);
st[x1][y1] = st[x2][y2] = false; //回溯
}
}
int main()
{
st[3][3] = true;
dfs(3, 3);
cout << ans / 4 << endl; // 因为上下,左右都是对称的,所以除与4
return 0;
}
边栏推荐
- AcWing 1294. Cherry Blossom explanation
- 虚拟机Ping通主机,主机Ping不通虚拟机
- 安全测试涉及的测试对象
- Copie maître - esclave MySQL, séparation lecture - écriture
- [recommended by bloggers] C # generate a good-looking QR code (with source code)
- 一键提取pdf中的表格
- Development of C language standard
- There are three iPhone se 2022 models in the Eurasian Economic Commission database
- Did you forget to register or load this tag 报错解决方法
- 【博主推荐】C#生成好看的二维码(附源码)
猜你喜欢

Pytorch基础

Postman Interface Association

LeetCode #461 汉明距离

When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page

Knowledge Q & A based on Apache Jena

Dotnet replaces asp Net core's underlying communication is the IPC Library of named pipes

Error connecting to MySQL database: 2059 - authentication plugin 'caching_ sha2_ The solution of 'password'

Install mysql5.5 and mysql8.0 under windows at the same time

Detailed reading of stereo r-cnn paper -- Experiment: detailed explanation and result analysis

Basic use of redis
随机推荐
Neo4j installation tutorial
【博主推荐】C#MVC列表实现增删改查导入导出曲线功能(附源码)
Record a problem of raspberry pie DNS resolution failure
自动机器学习框架介绍与使用(flaml、h2o)
SSM integrated notes easy to understand version
Some notes of MySQL
Did you forget to register or load this tag
[download app for free]ineukernel OCR image data recognition and acquisition principle and product application
Invalid global search in idea/pychar, etc. (win10)
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
How to set up voice recognition on the computer with shortcut keys
The virtual machine Ping is connected to the host, and the host Ping is not connected to the virtual machine
Why can't STM32 download the program
Asp access Shaoxing tourism graduation design website
Software testing and quality learning notes 3 -- white box testing
[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP
QT creator support platform
Esp8266 at+cipstart= "", "", 8080 error closed ultimate solution
Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
MySQL other hosts cannot connect to the local database