当前位置:网站首页>[leetcode sword finger offer 10 - II. Frog jumping steps (simple)]
[leetcode sword finger offer 10 - II. Frog jumping steps (simple)]
2022-04-23 21:21:00 【Minaldo7】
subject :
A frog can jump up at a time 1 Stepped steps , You can jump on it 2 Stepped steps . Ask the frog to jump on one n How many jumps are there in the steps .
The answer needs to be modelled 1e9+7(1000000007), If the initial result of calculation is :1000000008, Please return 1.
Example 1:
Input :n = 2
Output :2
Example 2:
Input :n = 7
Output :21
Example 3:
Input :n = 0
Output :1
Tips :
0 <= n <= 100
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
The problem solving process :
class Solution {
public int numWays(int n) {
// if(n == 0 || n == 1) return 1;
// int front = 1, back = 1, fibn =0;
// for(int i = 2;i<=n;i++){
// fibn = front + back;
// if(fibn >= 1000000007)
// fibn -= 1000000007;
// front = back;
// back = fibn;
// }
// return fibn;
if(n <= 1) return 1;
int dp[] = new int[n+1];
dp[0] = 1;
dp[1] = 1;
//dp[2] = 2;
for(int i = 2; i < n+1; i++){
dp[i] = (dp[i-1] + dp[i-2])%1000000007;
}
return dp[n];
}
}
Execution results :
notes : Multiplication of large numbers , Why should we take modules for the permutation and combination of large numbers ?
because :1000000007 It's a prime number ( prime number ), The remainder of prime numbers can avoid the conflict of results to the greatest extent / repeat
版权声明
本文为[Minaldo7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/111/202204210544479549.html
边栏推荐
- opencv应用——以图拼图
- Flomo software recommendation
- Tencent cloud has two sides in an hour, which is almost as terrible as one side..
- Tensorflow1. X and 2 How does x read those parameters saved in CKPT
- 危机即机遇,远程办公效率为何会提升?
- MySQL数据库常识之储存引擎
- Linux中,MySQL的常用命令
- Addition, deletion, modification and query of advanced MySQL data (DML)
- 管道和xargs
- MySQL进阶之数据的增删改查(DML)
猜你喜欢
Rust更适合经验较少的程序员?
Fastdfs mind map
MySQL进阶之表的增删改查
CUDA, NVIDIA driver, cudnn download address and version correspondence
Graph traversal - BFS, DFS
What if Jenkins forgot his password
一文解决浏览器跨域问题
小米手机全球已舍弃“MI”品牌,全面改用“xiaomi”全称品牌
Addition, deletion, modification and query of advanced MySQL data (DML)
Flomo software recommendation
随机推荐
Pikachuxss how to get cookie shooting range, always fail to return to the home page
Awk example skills
DeNO 1.13.2 release
Alibaba cloud responded to the disclosure of user registration information
Tensorflow and pytorch middle note feature map size adjustment to achieve up sampling
wait、waitpid
Common commands of MySQL in Linux
3-5通过XSS获取cookie以及XSS后台管理系统的使用
How to learn software testing? Self study or training? After reading this article, you will understand
Opencv application -- jigsaw puzzle
IOT 设计与开发
GSI-ECM工程建设管理数字化平台
Google tries to use rust in Chrome
亚马逊和Epic将入驻,微软应用商城向第三方开放
中创存储|想要一个好用的分布式存储云盘,到底该怎么选
Send email to laravel
使用mbean 自动执行heap dump
1.整理华子面经--1
ROS learning notes - tutorial on the use of ROS