当前位置:网站首页>822. Walk the Grid
822. Walk the Grid
2022-07-31 00:57:00 【Hunter_Kevin】
题目
给定一个 n×m 的方格阵,沿着方格的边线走,从左上角 (0,0) 开始,每次只能往右或者往下走一个单位距离,问走到右下角 (n,m) 一共有多少种不同的走法.
输入格式
共一行,包含两个整数 n 和 m.
输出格式
共一行,包含一个整数,表示走法数量.
数据范围
1≤n,m≤10
输入样例:
2 3
输出样例:
10
深搜代码AC
#include <iostream>
using namespace std;
int n, m;
int res;
void dfs(int x, int y)
{
if(x == n && y == m)res++;//If the current position is at the end point
else
{
if(x < n) dfs(x+1,y);//如果可以往下走
if(y < m) dfs(x, y+1);//Go right if you can
}
}
int main()
{
cin >> n >> m;
dfs(0,0);
cout << res << endl;
return 0;
}
Array simulation wide search,爆内存
#include <iostream>
using namespace std;
const int N = 15;
int dx[] = {
0,1}, dy[] = {
1,0};
int bfs(int x, int y)
{
int res = 0;
int q[1000][2] = {
0};
int f = 0, t = 0;
q[t][0] = 0, q[t][1] = 0;
t++;
while(f != t)
{
int curX = q[f][0], curY = q[f][1];
f++;
if(curX == x && curY == y)res++;
for(int i = 0; i < 2; i++)
{
int tX = curX + dx[i], tY = curY + dy[i];
if(tX >= 0 && tX <= x && tY >= 0 && tY <= y)
{
q[t][0] = tX, q[t][1] = tY;
t++;
}
}
}
return res;
}
int main()
{
int n, m;
cin >> n >> m;
cout << bfs(n,m) << endl;
return 0;
}
边栏推荐
- MySQL notes under
- 射频器件的基本参数1
- Sping.事务的传播特性
- 【Yugong Series】July 2022 Go Teaching Course 017-IF of Branch Structure
- Artificial Intelligence and Cloud Security
- Oracle has a weird temporary table space shortage problem
- 查看zabbix-release-5.0-1.el8.noarch.rpm包内容
- 24. 请你谈谈单例模式的优缺点,注意事项,使用场景
- ShardingSphere read-write separation (8)
- ShardingSphere's public table combat (7)
猜你喜欢

一万了解 Gateway 知识点

typescript9 - common base types
Go 学习笔记(84)— Go 项目目录结构

场景之多数据源查询及数据下载问题

Mysql systemized JOIN operation example analysis

ShardingSphere之未分片表配置实战(六)

MySQL table design for message queue to store message data

无线模块的参数介绍和选型要点

VS warning LNK4099:未找到 PDB 的解决方案
Go study notes (84) - Go project directory structure
随机推荐
BOM系列之history对象
WMware Tools installation failed segmentation fault solution
[Yugong Series] July 2022 Go Teaching Course 016-Logical Operators and Other Operators of Operators
【c语言课程设计】C语言校园卡管理系统
297. 二叉树的序列化与反序列化
4G通信模块CAT1和CAT4的区别
【Yugong Series】July 2022 Go Teaching Course 013-Constants, Pointers
ShardingSphere之水平分库实战(四)
ELK部署脚本---亲测可用
typescript10-commonly used basic types
论文理解:“Designing and training of a dual CNN for image denoising“
SereTOD2022 Track2代码剖析-面向半监督和强化学习的任务型对话系统挑战赛
Solution: Parameter 0 of method ribbonServerList in com.alibaba.cloud.nacos.ribbon.NacosRibbonClientConfigu
SereTOD2022 Track2 Code Analysis - Task-based Dialogue Systems Challenge for Semi-Supervised and Reinforcement Learning
过滤器(Filter)
A complete guide to avoiding pitfalls for the time-date type "yyyy-MM-dd HHmmss" in ES
Jmeter参数传递方式(token传递,接口关联等)
Artificial Intelligence and Cloud Security
ELK deployment script---pro test available
GO GOPROXY代理设置