当前位置:网站首页>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],一个月前的兔子也都会被归到下个月
边栏推荐
- [mathematical logic] propositions and connectives (propositions | propositional symbolization | truth connectives | no | conjunction | disjunction | non truth connectives | implication | equivalence)
- Ansible简介【暂未完成(半成品)】
- MongoDB复制集【主从复制】
- Limit of one question per day
- @Accessors annotation function specifies that the prefix follows the hump naming
- What happens between entering the URL and displaying the page?
- 静态网页 和 动态网页的区别 & WEB1.0和WEB2.0的区别 & GET 和 POST 的区别
- Mongodb replication set [master-slave replication]
- Captura下载安装及在Captura配置FFmpeg
- Mongodb installation & Deployment
猜你喜欢

MongoDB安装 & 部署

Idea format code idea set shortcut key format code

node,npm以及yarn下载安装

Why does thread crash not cause JVM crash

Hi3536c v100r001c02spc040 cross compiler installation

Captura下载安装及在Captura配置FFmpeg

用Three.js做一個簡單的3D場景

Pytoch configuration

Pat class B "1104 forever" DFS optimization idea
![[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)](/img/19/815e7cba81f6eb52db5ef0db556dfd.jpg)
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
随机推荐
Limit of one question per day
MongoDB主配置文件
Basic information of Promethus (I)
idea 加载不了应用市场解决办法(亲测)
VS 2019配置tensorRT
PAT乙级“1104 天长地久”DFS优化思路
Applet get user avatar and nickname
【PyG】理解MessagePassing过程,GCN demo详解
MySQL practice 45 lecture [transaction isolation]
Mongodb replication set [master-slave replication]
45 lectures on MySQL [index]
Pytorch轻量级可视化工具wandb(local)
Limit of one question per day
Idea format code idea set shortcut key format code
Spark on yarn资源优化思路笔记
Spark on yarn resource optimization ideas notes
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
MongoDB复制集【主从复制】
Captura下载安装及在Captura配置FFmpeg
MySql實戰45講【SQL查詢和更新執行流程】