auto commit
This commit is contained in:
parent
a15c26d4e4
commit
91a707eca6
|
@ -65,7 +65,7 @@ public int Fibonacci(int n) {
|
|||
}
|
||||
```
|
||||
|
||||
由于待求解的 n 小于 40,因此可以将前 40 项的结果先进行计算,之后就能以 O(1) 时间复杂度得到第 n 项的值了。
|
||||
由于待求解的 n 小于 40,因此可以将前 40 项的结果先进行计算,之后就能以 O(1) 时间复杂度得到第 n 项的值。
|
||||
|
||||
```java
|
||||
public class Solution {
|
||||
|
@ -96,6 +96,20 @@ public class Solution {
|
|||
|
||||
## 解题思路
|
||||
|
||||
当 n 为 1 时,只有一种覆盖方法:
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/fec3ba89-115a-4cf9-b165-756757644641.png" width="100px"> </div><br>
|
||||
|
||||
当 n 为 2 时,有两种覆盖方法:
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/db85a909-5e11-48b2-85d2-f003e7bb35c0.png" width="200px"> </div><br>
|
||||
|
||||
要覆盖 2\*n 的大矩形,可以先覆盖 2\*1 的矩形,再覆盖 2\*(n-1) 的矩形;或者先覆盖 2\*2 的矩形,再覆盖 2\*(n-2) 的矩形。而覆盖 2\*(n-1) 和 2\*(n-2) 的矩形可以看成子问题。该问题的递推公式如下:
|
||||
|
||||
<!-- <div align="center"><img src="https://latex.codecogs.com/gif.latex?f(n)=\left\{\begin{array}{rcl}1&&{n=1}\\2&&{n=2}\\f(n-1)+f(n-2)&&{n>1}\end{array}\right." class="mathjax-pic"/></div> <br> -->
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/508c6e52-9f93-44ed-b6b9-e69050e14807.jpg" width="350px"> </div><br>
|
||||
|
||||
```java
|
||||
public int RectCover(int n) {
|
||||
if (n <= 2)
|
||||
|
|
BIN
docs/pics/508c6e52-9f93-44ed-b6b9-e69050e14807.jpg
Normal file
BIN
docs/pics/508c6e52-9f93-44ed-b6b9-e69050e14807.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.9 KiB |
BIN
docs/pics/db85a909-5e11-48b2-85d2-f003e7bb35c0.png
Normal file
BIN
docs/pics/db85a909-5e11-48b2-85d2-f003e7bb35c0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
BIN
docs/pics/fec3ba89-115a-4cf9-b165-756757644641.png
Normal file
BIN
docs/pics/fec3ba89-115a-4cf9-b165-756757644641.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
notes/pics/508c6e52-9f93-44ed-b6b9-e69050e14807.jpg
Normal file
BIN
notes/pics/508c6e52-9f93-44ed-b6b9-e69050e14807.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.9 KiB |
BIN
notes/pics/db85a909-5e11-48b2-85d2-f003e7bb35c0.png
Normal file
BIN
notes/pics/db85a909-5e11-48b2-85d2-f003e7bb35c0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
BIN
notes/pics/fec3ba89-115a-4cf9-b165-756757644641.png
Normal file
BIN
notes/pics/fec3ba89-115a-4cf9-b165-756757644641.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
|
@ -65,7 +65,7 @@ public int Fibonacci(int n) {
|
|||
}
|
||||
```
|
||||
|
||||
由于待求解的 n 小于 40,因此可以将前 40 项的结果先进行计算,之后就能以 O(1) 时间复杂度得到第 n 项的值了。
|
||||
由于待求解的 n 小于 40,因此可以将前 40 项的结果先进行计算,之后就能以 O(1) 时间复杂度得到第 n 项的值。
|
||||
|
||||
```java
|
||||
public class Solution {
|
||||
|
@ -96,6 +96,20 @@ public class Solution {
|
|||
|
||||
## 解题思路
|
||||
|
||||
当 n 为 1 时,只有一种覆盖方法:
|
||||
|
||||
<div align="center"> <img src="pics/fec3ba89-115a-4cf9-b165-756757644641.png" width="100px"> </div><br>
|
||||
|
||||
当 n 为 2 时,有两种覆盖方法:
|
||||
|
||||
<div align="center"> <img src="pics/db85a909-5e11-48b2-85d2-f003e7bb35c0.png" width="200px"> </div><br>
|
||||
|
||||
要覆盖 2\*n 的大矩形,可以先覆盖 2\*1 的矩形,再覆盖 2\*(n-1) 的矩形;或者先覆盖 2\*2 的矩形,再覆盖 2\*(n-2) 的矩形。而覆盖 2\*(n-1) 和 2\*(n-2) 的矩形可以看成子问题。该问题的递推公式如下:
|
||||
|
||||
<!-- <div align="center"><img src="https://latex.codecogs.com/gif.latex?f(n)=\left\{\begin{array}{rcl}1&&{n=1}\\2&&{n=2}\\f(n-1)+f(n-2)&&{n>1}\end{array}\right." class="mathjax-pic"/></div> <br> -->
|
||||
|
||||
<div align="center"> <img src="pics/508c6e52-9f93-44ed-b6b9-e69050e14807.jpg" width="350px"> </div><br>
|
||||
|
||||
```java
|
||||
public int RectCover(int n) {
|
||||
if (n <= 2)
|
||||
|
|
Loading…
Reference in New Issue
Block a user