当前位置:网站首页>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],一个月前的兔子也都会被归到下个月
边栏推荐
- Lvgl usage experience
- Model transformation onnx2engine
- Vs Code configure virtual environment
- Vs 2019 configure tensorrt to generate engine
- Download and install node, NPM and yarn
- QT based tensorrt accelerated yolov5
- The calculation of stripe, kernel and padding in CNN
- MySql實戰45講【SQL查詢和更新執行流程】
- [leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
- Pytorch配置
猜你喜欢

VS 2019 配置tensorRT生成engine
![[MySQL] the difference between left join, right join and join](/img/d4/8684cd59cd1bd77e70bd4d7c7074c3.jpg)
[MySQL] the difference between left join, right join and join

User value is the last word in the competition of mobile phone market

Summary of electromagnetic spectrum

VS 2019配置tensorRT
![MySQL Real combat 45 [SQL query and Update Execution Process]](/img/cd/3a635f0c3bb4ac3c8241cb77285cc8.png)
MySQL Real combat 45 [SQL query and Update Execution Process]

Limit of one question per day

Vs Code configure virtual environment
![MySQL practice 45 lecture [row lock]](/img/71/344daddee537a96f0d38241e6896e1.png)
MySQL practice 45 lecture [row lock]

Spark on yarn资源优化思路笔记
随机推荐
[mathematical logic] propositions and connectives (propositions | propositional symbolization | truth connectives | no | conjunction | disjunction | non truth connectives | implication | equivalence)
Bigvision code
解决高并发下System.currentTimeMillis卡顿
MySQL practice 45 lecture [row lock]
ffmpeg之 一张/多张图片合成视频
MySql實戰45講【SQL查詢和更新執行流程】
VS 2019配置tensorRT
com. fasterxml. jackson. databind. Exc.invalidformatexception problem
[set theory] partial order relation (partial order relation definition | partial order set definition | greater than or equal to relation | less than or equal to relation | integer division relation |
为什么线程崩溃不会导致 JVM 崩溃
Spark on yarn resource optimization ideas notes
Yolov5 project based on QT
Mongodb installation & Deployment
解决高並發下System.currentTimeMillis卡頓
Pat class B common function Usage Summary
Don't use the new Dede collection without the updated Dede plug-in
Find the storage address of the elements in the two-dimensional array
Téléchargement et installation du client Filezilla
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output
VS 2019 配置tensorRT生成engine