当前位置:网站首页>leetcode:动态规划模板
leetcode:动态规划模板
2022-07-03 03:28:00 【我家大宝最可爱】
1. 数兔子
有一只兔子,从出生后第3个月起每个月都生一只兔子,小兔子长到第三个月后每个月又生一只兔子,假如兔子都不死,问每个月的兔子总数为多少?
我们假设第n-2个月的时候有dp[n-2]只兔子,第n-1个月的时候有dp[n-1]个兔子,那么第n个月有多少只兔子呢?第n个月的兔子一定是有第n-1个月的兔子来的,所以至少有dp[n-1]个兔子,但是同时呢,出生两个月的兔子都会再生一个兔子。出生两个月的兔子有多少了呢?往前推两个月的兔子就是当前出生两个月的兔子(废话文学),所以出生了两个月的兔子数量有dp[n-2]个,这些兔子会已经包含在了dp[n-1]之中,但是他们还会生dp[n-2]只兔子,所以dp[n]=dp[n-1]+dp[n-2]。
两个月前的兔子都会生一只兔子,那么两个月前有多少只兔子呢?答案就是dp[n-2],一个月前的兔子也都会被归到下个月
边栏推荐
- Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
- 用Three.js做一個簡單的3D場景
- Pytorch配置
- MySQL Real combat 45 [SQL query and Update Execution Process]
- FileZilla client download and installation
- Find the storage address of the elements in the two-dimensional array
- Applet get user avatar and nickname
- Spark on yarn resource optimization ideas notes
- [mathematical logic] propositions and connectives (propositions | propositional symbolization | truth connectives | no | conjunction | disjunction | non truth connectives | implication | equivalence)
- Application of derivative in daily question
猜你喜欢

Use of El tree search method

Introduction to mongodb

Spark on yarn resource optimization ideas notes

MongoDB安装 & 部署

ffmpeg之 一张/多张图片合成视频

softmax的近似之NCE详解

MongoDB复制集【主从复制】

Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check

【PyG】理解MessagePassing过程,GCN demo详解

Pytorch配置
随机推荐
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output
MySQL practice 45 [SQL query and update execution process]
[AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)
Bigvision code
使用InputFilter限制EditText时踩坑及解决方案
labelimg生成的xml文件转换为voc格式
Download and install node, NPM and yarn
Agile certification (professional scrum Master) simulation exercise-2
Node start server
VS 2019安装及配置opencv
Introduction to mongodb
MySQL MAC download and installation tutorial
机械臂速成小指南(八):运动学建模(标准DH法)
node 开启服务器
用Three.js做一個簡單的3D場景
ffmpeg下载安装教程及介绍
[combinatorics] number of solutions of indefinite equations (number of combinations of multiple sets R | number of non negative integer solutions of indefinite equations | number of integer solutions
VS 2019 配置tensorRT生成engine
Docker install and start MySQL service
Don't use the new Dede collection without the updated Dede plug-in