当前位置:网站首页>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 !
边栏推荐
- Ping domain name error unknown host, NSLOOKUP / system d-resolve can be resolved normally, how to Ping the public network address?
- Where is the win11 automatic shutdown setting? Two methods of setting automatic shutdown in win11
- Prometheus deployment
- CDN 加速,需要域名先备案
- Ideal car × Oceanbase: when the new forces of car building meet the new forces of database
- 万物并作,吾以观复|OceanBase 政企行业实践
- JDBC教程
- Arduino - 字符判断函数
- Quantitative analysis of PSNR, SSIM and RMSE
- "A good programmer is worth five ordinary programmers!"
猜你喜欢

一文掌握基于深度学习的人脸表情识别开发(基于PaddlePaddle)

Remote connection of raspberry pie by VNC viewer
![[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)](/img/93/dc940caebe176177e4323317ebf4fa.jpg)
[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)

Yolox enhanced feature extraction network panet analysis

BBR encounters cubic

(毒刺)利用Pystinger Socks4上线不出网主机

MySQL Foundation

Cryptography -- the mode of block cipher

Win11自动关机设置在哪?Win11设置自动关机的两种方法

4 special cases! Schools in area a adopt the re examination score line in area B!
随机推荐
Tiktok actual combat ~ number of likes pop-up box
Request and response
CDN acceleration requires the domain name to be filed first
Brief introduction to common sense of Zhongtai
Markdown basic grammar
A single element in an ordered array -- Valentine's Day mental problems
[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)
[ml] Li Hongyi III: gradient descent & Classification (Gaussian distribution)
Connexion à distance de la tarte aux framboises en mode visionneur VNC
What can I do after buying a domain name?
Mapper agent development
RuntimeError: no valid convolution algorithms available in CuDNN
Explain promise usage in detail
Wechat applet basic learning (wxss)
Implementation of VGA protocol based on FPGA
【ML】李宏毅三:梯度下降&分类(高斯分布)
Hisilicon VI access video process
Three solutions to frequent sticking and no response of explorer in win11 system
Print out mode of go
(毒刺)利用Pystinger Socks4上线不出网主机