Skip to content

Commit

Permalink
更新 完全背包理论基础 0139.单词拆分 0279.完全平方数 0322.零钱兑换 0377.组合总和IV 0518.零钱兑换II 多重…
Browse files Browse the repository at this point in the history
…背包理论基础 背包总结篇 排版格式修复
  • Loading branch information
jinbudaily committed Jul 26, 2023
1 parent fc19feb commit 7ac2179
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 66 deletions.
23 changes: 13 additions & 10 deletions problems/0139.单词拆分.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
* 输入: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
* 输出: false

# 算法公开课
## 算法公开课

**《代码随想录》算法视频公开课:[你的背包如何装满?| LeetCode:139.单词拆分](https://www.bilibili.com/video/BV1pd4y147Rh/),相信结合视频再看本篇题解,更有助于大家对本题的理解**
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[你的背包如何装满?| LeetCode:139.单词拆分](https://www.bilibili.com/video/BV1pd4y147Rh/),相信结合视频再看本篇题解,更有助于大家对本题的理解**


## 思路
Expand Down Expand Up @@ -123,7 +123,7 @@ public:
**这个代码就可以AC了,当然回溯算法不是本题的主菜,背包才是!**
## 背包问题
### 背包问题
单词就是物品,字符串s就是背包,单词能否组成字符串s,就是问物品能不能把背包装满。
Expand Down Expand Up @@ -239,7 +239,7 @@ public:

}
};
```
```

使用用例:s = "applepenapple", wordDict = ["apple", "pen"],对应的dp数组状态如下:

Expand All @@ -259,8 +259,8 @@ public:

## 其他语言版本

### Java:

Java:
```java
class Solution {
public boolean wordBreak(String s, List<String> wordDict) {
Expand Down Expand Up @@ -335,7 +335,7 @@ class Solution {
}
```

Python:
### Python:

回溯
```python
Expand Down Expand Up @@ -397,7 +397,8 @@ class Solution:



Go:
### Go:

```Go
func wordBreak(s string,wordDict []string) bool {
wordDictSet := make(map[string]bool)
Expand Down Expand Up @@ -433,7 +434,8 @@ func wordBreak(s string, wordDict []string) bool {
}
```

Javascript:
### JavaScript:

```javascript
const wordBreak = (s, wordDict) => {

Expand All @@ -454,7 +456,7 @@ const wordBreak = (s, wordDict) => {
}
```

TypeScript:
### TypeScript:

> 动态规划

Expand Down Expand Up @@ -496,7 +498,7 @@ function wordBreak(s: string, wordDict: string[]): boolean {
};
```

Rust:
### Rust:

```rust
impl Solution {
Expand All @@ -519,3 +521,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

21 changes: 11 additions & 10 deletions problems/0279.完全平方数.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
提示:
* 1 <= n <= 10^4

# 算法公开课
## 算法公开课

**《代码随想录》算法视频公开课:[换汤不换药!| LeetCode:279.完全平方数](https://www.bilibili.com/video/BV12P411T7Br/),相信结合视频再看本篇题解,更有助于大家对本题的理解**
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[换汤不换药!| LeetCode:279.完全平方数](https://www.bilibili.com/video/BV12P411T7Br/),相信结合视频再看本篇题解,更有助于大家对本题的理解**


## 思路
Expand Down Expand Up @@ -106,8 +106,6 @@ dp[5] = min(dp[4] + 1, dp[1] + 1) = 2
最后的dp[n]为最终结果。
## C++代码
以上动规五部曲分析完毕C++代码如下:
```CPP
Expand Down Expand Up @@ -165,8 +163,8 @@ public:
## 其他语言版本
### Java:
Java:
```Java
class Solution {
// 版本一,先遍历物品, 再遍历背包
Expand Down Expand Up @@ -219,7 +217,7 @@ class Solution {
}
```

Python:
### Python:

先遍历物品, 再遍历背包
```python
Expand Down Expand Up @@ -276,7 +274,8 @@ class Solution:


```
Go:
### Go:

```go
// 版本一,先遍历物品, 再遍历背包
func numSquares1(n int) int {
Expand Down Expand Up @@ -327,7 +326,8 @@ func min(a, b int) int {
}
```

Javascript:
### Javascript:

```Javascript
// 先遍历物品,再遍历背包
var numSquares1 = function(n) {
Expand Down Expand Up @@ -357,7 +357,7 @@ var numSquares2 = function(n) {
};
```

TypeScript:
### TypeScript:

```typescript
// 先遍历物品
Expand Down Expand Up @@ -389,7 +389,7 @@ function numSquares(n: number): number {
};
```

Rust:
### Rust:

```rust
// 先遍历背包
Expand Down Expand Up @@ -439,3 +439,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

20 changes: 11 additions & 9 deletions problems/0322.零钱兑换.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
* 1 <= coins[i] <= 2^31 - 1
* 0 <= amount <= 10^4

# 算法公开课
## 算法公开课

**《代码随想录》算法视频公开课:[装满背包最少的物品件数是多少?| LeetCode:322.零钱兑换](https://www.bilibili.com/video/BV14K411R7yv/),相信结合视频再看本篇题解,更有助于大家对本题的理解**
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[装满背包最少的物品件数是多少?| LeetCode:322.零钱兑换](https://www.bilibili.com/video/BV14K411R7yv/),相信结合视频再看本篇题解,更有助于大家对本题的理解**



Expand Down Expand Up @@ -110,7 +110,6 @@ dp[0] = 0;

dp[amount]为最终结果。

## C++代码
以上分析完毕,C++ 代码如下:

```CPP
Expand Down Expand Up @@ -187,8 +186,8 @@ public:

## 其他语言版本

### Java:

Java:
```Java
class Solution {
public int coinChange(int[] coins, int amount) {
Expand All @@ -215,7 +214,7 @@ class Solution {
}
```
Python:
### Python:
先遍历物品 后遍历背包
Expand Down Expand Up @@ -288,7 +287,8 @@ class Solution:

```

Go:
### Go:

```go
// 版本一, 先遍历物品,再遍历背包
func coinChange1(coins []int, amount int) int {
Expand Down Expand Up @@ -352,7 +352,7 @@ func min(a, b int) int {

```

Rust:
### Rust:

```rust
// 遍历物品
Expand Down Expand Up @@ -398,7 +398,8 @@ impl Solution {
}
```

Javascript:
### Javascript:

```javascript
// 遍历物品
const coinChange = (coins, amount) => {
Expand Down Expand Up @@ -435,7 +436,7 @@ var coinChange = function(coins, amount) {
}
```

TypeScript:
### TypeScript:

```typescript
// 遍历物品
Expand Down Expand Up @@ -473,3 +474,4 @@ function coinChange(coins: number[], amount: number): number {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

20 changes: 11 additions & 9 deletions problems/0377.组合总和Ⅳ.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

因此输出为 7。

# 算法公开课
## 算法公开课

**《代码随想录》算法视频公开课:[装满背包有几种方法?求排列数?| LeetCode:377.组合总和IV](https://www.bilibili.com/video/BV1V14y1n7B6/),相信结合视频再看本篇题解,更有助于大家对本题的理解**
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[装满背包有几种方法?求排列数?| LeetCode:377.组合总和IV](https://www.bilibili.com/video/BV1V14y1n7B6/),相信结合视频再看本篇题解,更有助于大家对本题的理解**

## 思路

Expand Down Expand Up @@ -154,8 +154,7 @@ C++测试用例有两个数相加超过int的数据,所以需要在if里加上
## 其他语言版本
Java:
### Java:
```Java
class Solution {
Expand All @@ -174,7 +173,7 @@ class Solution {
}
```

Python:
### Python:


卡哥版
Expand Down Expand Up @@ -207,7 +206,8 @@ class Solution:


```
Go:
### Go:

```go
func combinationSum4(nums []int, target int) int {
//定义dp数组
Expand All @@ -226,7 +226,8 @@ func combinationSum4(nums []int, target int) int {
}
```

Javascript:
### Javascript:

```javascript
const combinationSum4 = (nums, target) => {

Expand All @@ -245,7 +246,7 @@ const combinationSum4 = (nums, target) => {
};
```

TypeScript:
### TypeScript:

```typescript
function combinationSum4(nums: number[], target: number): number {
Expand All @@ -264,7 +265,7 @@ function combinationSum4(nums: number[], target: number): number {
};
```

Rust
### Rust:

```Rust
impl Solution {
Expand All @@ -289,3 +290,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

Loading

0 comments on commit 7ac2179

Please sign in to comment.