当前位置:网站首页>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],一个月前的兔子也都会被归到下个月
边栏推荐
- Nanning water leakage detection: warmly congratulate Guangxi Zhongshui on winning the first famous brand in Guangxi
- PHP constructor with parameters - PHP constructor with a parameter
- ffmpeg之 一张/多张图片合成视频
- Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
- 用Three.js做一個簡單的3D場景
- User value is the last word in the competition of mobile phone market
- Ansible introduction [unfinished (semi-finished products)]
- Use three JS make a simple 3D scene
- redis高级应用【密码防护、数据持久化、主从同步、哨兵模式、事务】【暂未完成(半成品)】
- [mathematical logic] normal form (conjunctive normal form | disjunctive normal form | major item | minor item | maximal item | minor item | principal conjunctive normal form | principal disjunctive no
猜你喜欢
MySQL Real combat 45 [SQL query and Update Execution Process]
FileZilla client download and installation
MongoDB簡介
ffmpeg下载安装教程及介绍
Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
node,npm以及yarn下载安装
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
navicat 导出数据库的表结构
Why does thread crash not cause JVM crash
Spark on yarn资源优化思路笔记
随机推荐
MySQL MAC download and installation tutorial
Limit of one question per day
文件重命名
Hi3536c v100r001c02spc040 cross compiler installation
The series of hyperbolic function in daily problem
UMI route interception (simple and rough)
MySQL practice 45 [SQL query and update execution process]
C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
VS 2019配置tensorRT
Pytoch lightweight visualization tool wandb (local)
The file marked by labelme is converted to yolov5 format
Agile certification (professional scrum Master) simulation exercise-2
Captura下载安装及在Captura配置FFmpeg
Tidal characteristics of the Bohai Sea and the Yellow Sea
403 error displayed when vs cloning
Idea format code idea set shortcut key format code
Avec trois. JS fait une scène 3D simple
Hi3536C V100R001C02SPC040 交叉编译器安装
用Three.js做一个简单的3D场景
MySql實戰45講【SQL查詢和更新執行流程】