当前位置:网站首页>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 
边栏推荐
- Tidal characteristics of the Bohai Sea and the Yellow Sea
- Pytorch轻量级可视化工具wandb(local)
- Why does thread crash not cause JVM crash
- 动态规划:最长回文子串和子序列
- Mongodb master profile
- On the adjacency matrix and adjacency table of graph storage
- Open Visual Studio 2010 hangs when opening a SQL file sql file
- 静态网页 和 动态网页的区别 & WEB1.0和WEB2.0的区别 & GET 和 POST 的区别
- PAT乙级常用函数用法总结
- sigaction的使用
猜你喜欢
![MySQL practice 45 lecture [transaction isolation]](/img/a5/5420651d6be51e892976f02be8c43c.png)
MySQL practice 45 lecture [transaction isolation]
![C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output](/img/38/9c460fc58b62609dd02e7c61207ae6.jpg)
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output

VS 2019配置tensorRT

Introduction à mongodb

Application of derivative in daily question

Ffmpeg one / more pictures synthetic video

渤、黄海的潮汐特征

Nanning water leakage detection: warmly congratulate Guangxi Zhongshui on winning the first famous brand in Guangxi

MySQL MAC download and installation tutorial

UMI route interception (simple and rough)
随机推荐
Node start server
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
[Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
Advanced redis applications [password protection, data persistence, master-slave synchronization, sentinel mode, transactions] [not completed yet (semi-finished products)]
Introduction à mongodb
Limit of one question per day
VS 2019 配置tensorRT生成engine
File rename
Solve high and send system Currenttimemillis Caton
docker安装及启动mysql服务
User value is the last word in the competition of mobile phone market
Limit of one question per day
[MySQL] the difference between left join, right join and join
labelimg生成的xml文件转换为voc格式
MySQL MAC download and installation tutorial
MongoDB簡介
递归:深度优先搜索
ffmpeg之 一张/多张图片合成视频
Ansible简介【暂未完成(半成品)】
Hi3536c v100r001c02spc040 cross compiler installation