当前位置:网站首页>Leetcode question bank 62 Different paths (recursive C implementation)
Leetcode question bank 62 Different paths (recursive C implementation)
2022-04-22 21:51:00 【Liujiashan No.1 miner】
Ideas
Method 1
The only direction you can choose is the right 、 Next , Every time I get to a position , Except the right is the bottom , Same as its previous state , Satisfy recursive structure
So you can use recursion to simulate
x、y Used to record the current position ,m、n Is the end position
When x < m、y < n when , Go in both directions at the same time
That is to say
f(x+1,y,m,n);
f(x,y+1,m,n);
When x < m、y = n when , Go to x Go in the direction
f(x+1,y,m,n);
When x = m、y < n when , Go to y Go in the direction
f(x,y+1,m,n);
Only when x = m、y = n when , Indicates that we have reached the end ,ret+1
Method 2
This problem can also be done with permutations and combinations , The implementation is also relatively simple
effect
There's no problem with the code , The test case tests out as expected
But after submission, the same input also has different outputs , It should be the platform

Code
long long ret=0;
void f(int x, int y, int m, int n){
if(x==m && y==n){
ret++;
}
else{
if(x < m && y < n){
f(x+1,y,m,n);
f(x,y+1,m,n);
}
else{
if(x < m && y == n){
f(x+1,y,m,n);
}
else{
f(x,y+1,m,n);
}
}
}
}
long long uniquePaths(int m, int n) {
f(0,0,m-1,n-1);
return ret;
}
版权声明
本文为[Liujiashan No.1 miner]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221625058895.html
边栏推荐
- Solving SCP command secret free login in shell script
- 好的测试数据管理,到底要怎么做?
- 如何在项目中引入SPI
- Several innovative economic models of platefarm have inspired the current meta universe market
- 故障分析 | Federated 存储引擎表导致监控线程处于 Opening table 状态
- 短视频内容理解与生成技术在美团的创新实践
- alsa播放结束时的杂音问题
- What completely self-developed computer hardware do we have?
- ES6 object extension chain judgment operator and null judgment operator
- What important accessories are included in the M5 enhanced dual system package and how to choose?
猜你喜欢

實驗3

1251 - client does not support authentication protocol error in MySQL running in Navicat for MySQL connection docker

未來源碼 | 吳恩達教授重磅演講:Tips for using a data-centric AI approach

MySQL log

利用反向传播训练多层神经网络的原理

线程通信机制:共享内存 VS 消息传递

Enterprise appraisers build a decision support platform for the government

Online yaml to XML tool

Prediction of loan risk with keras logistic regression

Future source | Prof. Wu Enda Heavy Speech: Tips for Using a data Centric ai Approach
随机推荐
paho.mqtt.c使用的总结
Collect excellent blog articles
Pushing hand of industrial Internet innovation iteration
实验3
glib 和 glibc
Interface test mock practice (II) | complete batch manual mock in combination with JQ
CSV Column Extract列提取
【面试技巧】无领导小组面试怎么面
Uclibc is different from glibc
ES6 proxy and object defineProperty
【报名】TF54:工程师成长地图与卓越研发组织打造
leetcode - 234. Palindrome linked list
Alibaba cloud container & Service Grid product technology trends (202203)
Spark-2.4.2 compilation and installation
Leaflet修改地图中心点定位
[electron] file download stuck
Old saying: MySQL architecture
實驗3
EMMC 擦除组的理解
Embedded design and development project - digital tube static display program design