当前位置:网站首页>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
边栏推荐
- [leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
- New programmers use the isXXX form to define Boolean types in the morning, and are discouraged in the afternoon?
- shardingsphere动态数据源
- Open Visual Studio 2010 hangs when opening a SQL file sql file
- 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
- C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
- Captura下载安装及在Captura配置FFmpeg
- leetcode:动态规划模板
- Model transformation onnx2engine
- Compare float with 0
猜你喜欢
MySQL practice 45 lecture [transaction isolation]
Pytoch lightweight visualization tool wandb (local)
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
Pytorch轻量级可视化工具wandb(local)
用Three.js做一個簡單的3D場景
MongoDB简介
softmax的近似之NCE详解
node,npm以及yarn下载安装
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
Avec trois. JS fait une scène 3D simple
随机推荐
程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
FileZilla Client下載安裝
用Three.js做一个简单的3D场景
监听对象中值变化及访问
渤、黄海的潮汐特征
The calculation of stripe, kernel and padding in CNN
navicat 导出数据库的表结构
Téléchargement et installation du client Filezilla
MongoDB安装 & 部署
C语言HashTable/HashSet库汇总
Converts a timestamp to a time in the specified format
MySQL practice 45 lecture [row lock]
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息
MongoDB基本操作【增、删、改、查】
Ansible简介【暂未完成(半成品)】
动态规划:最长回文子串和子序列
900W+ 数据,从 17s 到 300ms,如何操作
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions