当前位置:网站首页>Luogu p3654 fisrt step
Luogu p3654 fisrt step
2022-06-13 05:00:00 【Clown clown clown】
Topic link :First Step
Knowledge point : A straight line dfs
A straight line dfs It means to follow a path to the end , Can't turn .
In this problem, you can go straight to the right or down dfs.
Down dfs
void down(int x, int y)
{
if( Meet the end condition )
{
Do what you have to do ;
return;
}
int newx = x + dir[0][0], newy = y + dir[0][1];// Down
if (newx >= 0 && newx < n && newy >= 0 && newy < m && g[newx][newy] == '.')
{
Do what you have to do ;
down(newx, newy);
}
}
towards the right dfs It's the same way .
In this category , For each point dfs.( It's kind of like the island issue . But the island problem is general dfs You can turn .) So we have to go through the two-dimensional matrix .
AC Code :
#include <iostream>
using namespace std;
const int N = 110;
char g[N][N];
int dir[2][2] = {
{
1,0},{
0,1}};
int n, m, k;
int ans;
int cnt;
void down(int x, int y)
{
if (cnt == k - 1)
{
ans++;
return;
}
int newx = x + dir[0][0], newy = y + dir[0][1];// Down
if (newx >= 0 && newx < n && newy >= 0 && newy < m && g[newx][newy] == '.')
{
cnt++;
down(newx, newy);
}
}
void right(int x, int y)
{
if (cnt == k - 1)
{
ans++;
return;
}
int newx = x + dir[1][0], newy = y + dir[1][1];// towards the right
if (newx >= 0 && newx < n && newy >= 0 && newy < m && g[newx][newy] == '.')
{
cnt++;
right(newx, newy);
}
}
int main()
{
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> g[i][j];
// Traverse every point
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (g[i][j] == '.')
{
down(i, j);
cnt = 0;
right(i, j);
cnt = 0;
}
}
}
if (k == 1) ans /= 2;
cout << ans;
}
notes : In this problem , If k be equal to 1, Then the count is repeated to the right and down , Divide by 2.
边栏推荐
- C language learning log 12.5
- Introduction to QT XML
- Common skills in embedded programming
- The processing flow of thread pool depends on the core parameters
- Brick story
- The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
- Section 5 - Operator details
- C language learning log 1.22
- QT interface rendering style
- C language learning log 12.25
猜你喜欢

CMB's written test -- data analysis

What is the difference between ROM, ram and flash? SRAM、DRAM、PROM、EPROM、EEPROM

Configuration used by automatic teaching evaluation script

Robot pose description and coordinate transformation

Hidden implementation and decoupling, knowing Pimpl mode

RuoYi-Cloud启动教程(手把手图文)

SQL notes

Advanced C language - Section 1 - data storage

使用EasyDarwin+FFmpeg实现rtsp推流

Optocoupler working principle function electric parameter application circuit
随机推荐
What is the difference between ROM, ram and flash? SRAM、DRAM、PROM、EPROM、EEPROM
Advanced C - Section 2 - pointers
OJ problem solution summary
Mysql8.0.13 installation tutorial (with pictures)
Force deduction 121 questions
Introduction to QT XML
Keil uses j-link to burn the code, and an error occurs: Flash download failed - one of the "Cortex-M3" solutions
利用Javeswingjdbc基于mvc设计系统
josephus problem
[leetcode]- binary search
Regular expressions in QT
C language learning log 10.10
Force buckle 92 Reverse linked list II
Configuration used by automatic teaching evaluation script
[leetcode]- sliding window
Win8.1和Win10各自的優勢
Conception d'un système basé sur MVC avec javaswing JDBC
Chapter 15 mechanism: Address Translation
C language learning log 10.4
Clause 33: decltype is used for auto & type formal parameters, with std:: forward