当前位置:网站首页>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],一个月前的兔子也都会被归到下个月
边栏推荐
- User value is the last word in the competition of mobile phone market
- Unity3d RPG implementation (medium)
- C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
- 用Three.js做一个简单的3D场景
- Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)
- MySQL practice 45 [SQL query and update execution process]
- Pytoch configuration
- Mysql Mac版下载安装教程
- Why does thread crash not cause JVM crash
- C # general interface call
猜你喜欢
![Mongodb replication set [master-slave replication]](/img/2c/8030548455f45fa252062dd90e7b8b.png)
Mongodb replication set [master-slave replication]

LVGL使用心得

numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences

VS code配置虚拟环境

FileZilla Client下载安装

Pytoch lightweight visualization tool wandb (local)

docker安装及启动mysql服务

Vs 2019 configuration tensorrt

Vs Code configure virtual environment

Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check
随机推荐
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
ffmpeg下载安装教程及介绍
MySQL MAC download and installation tutorial
Limit of one question per day
Téléchargement et installation du client Filezilla
MongoDB基本操作【增、删、改、查】
Avec trois. JS fait une scène 3D simple
Pat class B common function Usage Summary
ffmpeg之 一张/多张图片合成视频
Node start server
MySQL practice 45 lecture [transaction isolation]
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
【PyG】理解MessagePassing过程,GCN demo详解
idea 加载不了应用市场解决办法(亲测)
Vs 2019 configure tensorrt to generate engine
The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled
Ansible简介【暂未完成(半成品)】
PAT乙级常用函数用法总结
Use three JS make a simple 3D scene
The series of hyperbolic function in daily problem