当前位置:网站首页>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 
边栏推荐
- 动态规划:最长回文子串和子序列
- Mongodb master profile
- Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
- Summary of electromagnetic spectrum
- [AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)
- Vs Code configure virtual environment
- Pytorch配置
- 递归使用和多维数组对象变一维数组对象
- Lvgl usage experience
- Mongodb installation & Deployment
猜你喜欢

navicat 导出数据库的表结构

递归:深度优先搜索

Table structure of Navicat export database

Don't use the new Dede collection without the updated Dede plug-in

Gavin teacher's perception of transformer live class - rasa project's actual banking financial BOT Intelligent Business Dialogue robot architecture, process and phenomenon decryption through rasa inte

Summary of electromagnetic spectrum

VS 2019 配置tensorRT生成engine
![MySQL practice 45 lecture [transaction isolation]](/img/a5/5420651d6be51e892976f02be8c43c.png)
MySQL practice 45 lecture [transaction isolation]

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!

Vs 2019 configuration du moteur de génération de tensorrt
随机推荐
Docker install and start MySQL service
PAT乙级常用函数用法总结
The series of hyperbolic function in daily problem
The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled
MongoDB复制集【主从复制】
labelimg生成的xml文件转换为voc格式
[algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
softmax的近似之NCE详解
node 开启服务器
[mathematical logic] propositional logic (propositional logic reasoning | formal structure of reasoning | inference law | additional law | simplification law | hypothetical reasoning | refusal | disju
VS code配置虚拟环境
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
用Three.js做一個簡單的3D場景
PAT乙级“1104 天长地久”DFS优化思路
[mathematical logic] propositional logic (propositional and connective review | propositional formula | connective priority | truth table satisfiable contradiction tautology)
渤、黄海的潮汐特征
Node start server
@The difference between Autowired, @qualifier, @resource
[set theory] partial order relation (partial order relation definition | partial order set definition | greater than or equal to relation | less than or equal to relation | integer division relation |
Small guide for rapid formation of manipulator (VIII): kinematic modeling (standard DH method)