当前位置:网站首页>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.
边栏推荐
- Win8.1和Win10各自的優勢
- Chapter 18 pagination: Introduction
- OJ problem solution summary
- Clause 27: alternatives to overloading with familiar universal reference types
- C language learning log 1.2
- Embedded hardware - read schematic
- 1.2 differences caused by keywords
- How to use redis
- C # get all callable methods of WebService interface [webmethod]
- C language learning log 12.5
猜你喜欢
Advanced C - Section 2 - pointers
Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution論文淺析
Explain the differences and usage scenarios between created and mounted
Section 2 - branch and loop statements
Avantages de win8.1 et win10
Kaggle 时间序列教程
Simple sr: Best Buddy Gans for highly detailed image super resolution Paper Analysis
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
Analysis of scoped attribute principle and depth action selector
Embedded hardware: electronic components (1) resistance capacitance inductance
随机推荐
Regular expressions in QT
C language learning log 10.8
1.2 differences caused by keywords
Little C's Notepad
Shell variable learning notes
Gradient descent, learning rate
Clause 47: please use traits classes to represent type information
小C的记事本
Kaggle 时间序列教程
Article 29: assuming that the mobile operation does not exist, is expensive, and is not used
Bm1z002fj-evk-001 startup evaluation
JS to realize the conversion between string and array and an interview question
C language exercise 1
C language learning log 10.19
C language learning log 1.17
利用Javeswingjdbc基於mvc設計系統
How to understand JS expressions and JS statements
rainbow
Solution to sudden font change in word document editing
Cesium:cesiumlab makes image slices and loads slices