当前位置:网站首页>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 
边栏推荐
- 监听对象中值变化及访问
- Pytorch multi card distributed training distributeddataparallel usage
- 动态规划:最长公共子串和最长公共子序列
- shardingsphere动态数据源
- Vs 2019 configuration tensorrt
- VS 2019配置tensorRT
- 动态规划:最长回文子串和子序列
- [embedded module] OLED display module
- Application of derivative in daily question
- Pat class B common function Usage Summary
猜你喜欢

ffmpeg录制屏幕和截屏

Summary of electromagnetic spectrum

Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0

递归:快速排序,归并排序和堆排序

Vs 2019 configuration tensorrt

Table structure of Navicat export database
![C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions](/img/4a/1df03d9f3315debb4c335260ed39f2.jpg)
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions

Application of derivative in daily question
![MySQL practice 45 lecture [row lock]](/img/71/344daddee537a96f0d38241e6896e1.png)
MySQL practice 45 lecture [row lock]

MongoDB簡介
随机推荐
[mathematical logic] propositional logic (propositional logic reasoning | formal structure of reasoning | inference law | additional law | simplification law | hypothetical reasoning | refusal | disju
Limit of one question per day
@The difference between Autowired, @qualifier, @resource
Converts a timestamp to a time in the specified format
FileZilla Client下载安装
Tidal characteristics of the Bohai Sea and the Yellow Sea
Limit of one question per day
Basic operations of mongodb [add, delete, modify, query]
VS 2019安装及配置opencv
Pat class B "1104 forever" DFS optimization idea
解决高並發下System.currentTimeMillis卡頓
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
Applet get user avatar and nickname
MySQL practice 45 lecture [transaction isolation]
The XML file generated by labelimg is converted to VOC format
PHP generates PDF tcpdf
Avec trois. JS fait une scène 3D simple
navicat 导出数据库的表结构
The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled
com.fasterxml.jackson.databind.exc.InvalidFormatException问题