当前位置:网站首页>Leetcode: dynamic planning template
Leetcode: dynamic planning template
2022-07-03 03:32:00 【My family Dabao is the cutest】
1. Count rabbits
There is a rabbit , From the day after birth 3 A rabbit has been born every month since last month , The little rabbit grows to the third month and gives birth to another rabbit every month , If the rabbits don't die , Ask the total number of rabbits per month ?
Let's assume that No n-2 When I was six months old dp[n-2] A rabbit , The first n-1 When I was six months old dp[n-1] A rabbit , So the first n How many rabbits are there in a month ? The first n A month old rabbit must have a first n-1 A month old rabbit came , So at least dp[n-1] A rabbit , But at the same time , Rabbits born two months old will have another rabbit . How many rabbits are there two months old ? The rabbit that is pushed forward for two months is the rabbit that is currently born for two months ( Nonsense Literature ), So the number of rabbits born two months is dp[n-2] individual , These rabbits will already be included dp[n-1] In , But they will also have dp[n-2] A rabbit , therefore dp[n]=dp[n-1]+dp[n-2].
Rabbits two months ago will have a rabbit , How many rabbits were there two months ago ? The answer is dp[n-2], Rabbits one month ago will also be classified as next month 
边栏推荐
- PAT乙级“1104 天长地久”DFS优化思路
- Réglez la hauteur et lancez le système. Currenttimemillis catton
- Model transformation onnx2engine
- 基于QT的tensorRT加速的yolov5
- MongoDB主配置文件
- 动态规划:最长公共子串和最长公共子序列
- Hi3536C V100R001C02SPC040 交叉编译器安装
- Docker install and start MySQL service
- Use three JS make a simple 3D scene
- @Accessors annotation function specifies that the prefix follows the hump naming
猜你喜欢

VS code配置虚拟环境

The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled

npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

FileZilla client download and installation

机械臂速成小指南(八):运动学建模(标准DH法)

ffmpeg下载安装教程及介绍

FileZilla Client下載安裝

小程序获取用户头像和昵称
![[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)

Ffmpeg one / more pictures synthetic video
随机推荐
简易版 微信小程序开发之for指令、上传图片及展示效果优化
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
umi 路由拦截(简单粗暴)
Limit of one question per day
动态规划:最长回文子串和子序列
docker安装及启动mysql服务
The series of hyperbolic function in daily problem
用Three.js做一個簡單的3D場景
FileZilla Client下載安裝
Introduction à mongodb
Using jasmine to monitor constructors - spying on a constructor using Jasmine
Advanced redis applications [password protection, data persistence, master-slave synchronization, sentinel mode, transactions] [not completed yet (semi-finished products)]
Use three JS make a simple 3D scene
@Accessors注解作用指定前缀遵守驼峰命名
[combinatorics] basic counting principle (addition principle | multiplication principle)
com.fasterxml.jackson.databind.exc.InvalidFormatException问题
shardingsphere动态数据源
Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check
sigaction的使用
Mongodb master profile