当前位置:网站首页>Leetcode DP three step problem
Leetcode DP three step problem
2022-07-02 23:33:00 【qq5924db5b70f63】
package dp.waysToStep;
/**
* Interview questions 08.01. Three step problem
* Three step problem . There is a child going up the stairs , The stairs have n Steps , Children can go to 1 rank 、2 Step or 3 rank . Implement a way , Calculate how many ways a child can go up stairs . The results could be big , You need to model the results 1000000007.
* <p>
* Example 1:
* <p>
* Input :n = 3
* Output :4
* explain : There are four ways to walk
* Example 2:
* <p>
* Input :n = 5
* Output :13
* Tips :
* <p>
* n The scope is [1, 1000000] Between
*/
public class waysToStep {
public static int waysToStep(int n) {
int size = n<3?3:n;
int[] dp = new int[size];
dp[0] = 1;
dp[1] = 2;
dp[2] = 4;
for (int i = 3; i < n; i++) {
//dp[i-3] The mold has been taken in the last step , The remaining two to prevent overflow also need to take the mold
dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007 + dp[i - 3];
dp[i] %= 1000000007;
}
return dp[n-1];
}
public static void main(String[] args) {
System.out.println(waysToStep(1));
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
Can't , I can learn ; backward , I can catch up ; Fall down , I can stand up !
边栏推荐
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验3 按键输入实验(学习笔记)
- Eight bit responder [51 single chip microcomputer]
- Li Kou brush questions (2022-6-28)
- 20220524_ Database process_ Statement retention
- golang中new与make的区别
- LINQ usage collection in C #
- How difficult is it to be high? AI rolls into the mathematics circle, and the accuracy rate of advanced mathematics examination is 81%!
- 跨境电商如何通过打好数据底座,实现低成本稳步增长
- Boost库链接错误解决方案
- Dishes launcher small green program and directory management (efficiency tool)
猜你喜欢

请求与响应

Go project operation method

Fusion de la conversion et de la normalisation des lots

2022 latest and complete interview questions for software testing

Potplayer set minimized shortcut keys

Markdown basic grammar

【直播预约】数据库OBCP认证全面升级公开课

FOC矢量控制及BLDC控制中的端电压、相电压、线电压等概念别还傻傻分不清楚

RuntimeError: no valid convolution algorithms available in CuDNN

JDBC practice cases
随机推荐
Submit code process
Print out mode of go
高数有多难?AI 卷到数学圈,高数考试正确率 81%!
PHP get real IP
【直播预约】数据库OBCP认证全面升级公开课
Temperature measurement and display of 51 single chip microcomputer [simulation]
golang中new与make的区别
The concepts of terminal voltage, phase voltage and line voltage in FOC vector control and BLDC control are still unclear
Markdown basic grammar
面试过了,起薪16k
抖音实战~点赞数量弹框
【Redis笔记】压缩列表(ziplist)
SharedPreferences save list < bean > to local and solve com google. gson. internal. Linkedtreemap cannot be cast to exception
基于FPGA的VGA协议实现
Data set - fault diagnosis: various data and data description of bearings of Western Reserve University
Is 408 not fragrant? The number of universities taking the 408 examination this year has basically not increased!
Boost库链接错误解决方案
[live broadcast appointment] database obcp certification comprehensive upgrade open class
Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]
Writing of head and bottom components of non routing components