This commit is contained in:
SunnyQjm committed 2020-04-16 18:28:04 +08:00
1 parent 759ca52e4d
commit 731271a5d0
38 files changed
+208 -103

No files matched your search

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Regular → Executable
View File
File mode changed.
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Regular → Executable
View File
File mode changed.
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Regular → Executable
View File
File mode changed.
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Regular → Executable
View File
File mode changed.
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Regular → Executable
View File
File mode changed.
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Regular → Executable
View File
File mode changed.
Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 KiB

+105
View File
@@ -0,0 +1,105 @@
# Algorithm Homework 7
> 姓名:阙建明
>
> 学号:1901213139
## 作业要求:
![](AlgorithmHomework7.assets/微信图片_20200416172437.jpg)
## 题解:
- ### 背包问题
- **算法思路:**
- 使用动态规划的思想;
- 状态转移方程如下:
$P(i, j) = \begin{cases}True &\text{if } P(i + 1, j - 1)==True , S_i == S_j \\False &\text{if 其它 } \end{cases}$
- 首先判断长度为1的子串,再判断长度为2的子串,再判断长度为3的子串,以此类推。
- **Leetcode提交结果:**
![image-20200407102849523](AlgorithmHomework7.assets/image-20200407102849523.png)
- **代码:**
```python
class Solution:
def longestPalindrome(self, s: str) -> str:
arr = [[False] * len(s) for i in range(len(s))]
for i in range(len(s)):
arr[i][i] = True
maxLen, maxStrStart, maxStrEnd = 1, 0, 1
for span in range(1, len(s)):
left, right = 0, span
while right < len(s):
arr[left][right] = True if s[left] == s[right] and (span == 1 or arr[left + 1][right - 1]) else False
if arr[left][right] and right - left + 1 > maxLen:
maxLen, maxStrStart, maxStrEnd = right - left + 1, left, right + 1
left, right = left + 1, right + 1
return s[maxStrStart: maxStrEnd]
```
- ### Leetcode problem 64
> [最小路径和](https://leetcode-cn.com/problems/minimum-path-sum/)
- **算法思路:**
- 采用动态规划的思想,自右下角向左上脚遍历。
- 首先将最下面一排的路径开销自右往左以此叠加,把最右边一排的路径开销自下往上以此叠加,接着其它情况使用与下述状态转换方程:
$P(i, j) = \begin{cases}P(i, j) + P(i + 1, j) &\text{if } P(i, j + 1) >= P(j + 1) \\P(i, j) + P(i, j + 1) &\text{if }P(i, j + 1) < P(j + 1) \end{cases}$
- **Leetcode提交结果:**
![image-20200407105454180](AlgorithmHomework7.assets/image-20200407105454180.png)
- **代码:**
```python
class Solution:
def minPathSum(self, grid: List[List[int]]) -> int:
rowNum, colNum = len(grid), len(grid[0])
for col in range(colNum - 2, -1, -1):
grid[rowNum - 1][col] = grid[rowNum - 1][col] + grid[rowNum - 1][col + 1]
for row in range(rowNum - 2, -1, -1):
grid[row][colNum - 1] = grid[row][colNum - 1] + grid[row + 1][colNum - 1]
for col in range(colNum - 2, -1, -1):
for row in range(rowNum - 2, -1, -1):
grid[row][col] = grid[row][col] + min(grid[row + 1][col], grid[row][col + 1])
return grid[0][0]
```
- ### Leetcode problem 120
> [三角形最小路径和](https://leetcode-cn.com/problems/triangle/)
- **算法思路:**
- 用动态规划的思想,自底向上一次计算到当前访问节点到叶子节点的最短路径;
- 状态转移方程如下:
$P(row, index) = \begin{cases}P(row, index) &\text{if } row == len(triangle) - 1 \\P(row, index) + min(P(row + 1, index), P(row + 1, index + 1)) &\text{if }row < len(triangle) - 1 \end{cases}$
- **Leetcode提交结果:**
![image-20200407122505839](AlgorithmHomework7.assets/image-20200407122505839.png)
- **代码:**
```python
class Solution:
def minimumTotal(self, triangle: List[List[int]]) -> int:
for row in range(len(triangle) - 2, -1, -1):
for index in range(len(triangle[row])):
triangle[row][index] = triangle[row][index] + min(triangle[row + 1][index], triangle[row + 1][index + 1])
return triangle[0][0]
```
Regular → Executable
View File
File mode changed.
Regular → Executable
+103 -103
View File
@@ -1,103 +1,103 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>算法课作业-阙建明</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="description" content="Description">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.css">
<link href="//cdn.bootcss.com/prism/9000.0.1/themes/prism.min.css" rel="stylesheet">
<link rel="stylesheet" href="//unpkg.com/gitalk/dist/gitalk.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css"/>
</head>
<body>
<div id="app"></div>
<script src="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script src="//cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script>
function NewGitalk() {
let id = decodeURI(`${window.location.hash}`);
console.log(`id: ${id}`);
console.log(window.location);
const title = `Gitalk评论${decodeURI(window.location.pathname)}${window.location.hash}`;
if (id.length > 50) {
id = id.substr(0, 50);
}
return new Gitalk({
title: title,
clientID: 'fa290550335fbd43a74e',
clientSecret: '4c7ba77a9bb7f1f0694f29af4d18c00479bba5c6',
repo: 'nfd-developer-guide-zh',
owner: 'SunnyQjm',
admin: ['SunnyQjm'],
// facebook-like distraction free mode
distractionFreeMode: false
})
}
</script>
<script>
var num = 0;
mermaid.initialize({
startOnLoad: false,
flowchart: {
useMaxWidth: true,
htmlLabels: false,
curve: 'cardinal',
},
});
window.$docsify = {
name: '算法课作业',
repo: 'https://github.com/SunnyQjm/algorithm-homework',
autoHeader: true,
subMaxLevel: 4,
auto2top: true,
markdown: {
renderer: {
code: function (code, lang) {
if (lang === "mermaid") {
return (
'<div class="mermaid">' + mermaid.render('mermaid-svg-' + num++, code) + "</div>"
);
}
return this.origin.code.apply(this, arguments);
}
}
},
plugins: [
function(hook, vm) {
hook.doneEach(function(){
//const elem = document.getElementById('gitalk-container');
//elem && (elem.innerHTML = "");
//NewGitalk().render('gitalk-container');
});
}
]
};
$(document).ready(function () {
$('pre').addClass("line-numbers").css("white-space", "pre-wrap");
})
NewGitalk()
</script>
<script src="//unpkg.com/docsify-copy-code"></script>
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-c.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-cpp.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-python.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/zoom-image.min.js"></script>
<!-- CDN files for docsify-katex -->
<script src="//cdn.jsdelivr.net/npm/docsify-katex@latest/dist/docsify-katex.js"></script>
<!-- Gitalk 配置 -->
<script src="//unpkg.com/docsify/lib/plugins/gitalk.js"></script>
<script src="//unpkg.com/gitalk/dist/gitalk.min.js"></script>
<script>
const gitalk = NewGitalk()
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>算法课作业-阙建明</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="description" content="Description">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.css">
<link href="//cdn.bootcss.com/prism/9000.0.1/themes/prism.min.css" rel="stylesheet">
<link rel="stylesheet" href="//unpkg.com/gitalk/dist/gitalk.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css"/>
</head>
<body>
<div id="app"></div>
<script src="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script src="//cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script>
function NewGitalk() {
let id = decodeURI(`${window.location.hash}`);
console.log(`id: ${id}`);
console.log(window.location);
const title = `Gitalk评论${decodeURI(window.location.pathname)}${window.location.hash}`;
if (id.length > 50) {
id = id.substr(0, 50);
}
return new Gitalk({
title: title,
clientID: 'fa290550335fbd43a74e',
clientSecret: '4c7ba77a9bb7f1f0694f29af4d18c00479bba5c6',
repo: 'nfd-developer-guide-zh',
owner: 'SunnyQjm',
admin: ['SunnyQjm'],
// facebook-like distraction free mode
distractionFreeMode: false
})
}
</script>
<script>
var num = 0;
mermaid.initialize({
startOnLoad: false,
flowchart: {
useMaxWidth: true,
htmlLabels: false,
curve: 'cardinal',
},
});
window.$docsify = {
name: '算法课作业',
repo: 'https://github.com/SunnyQjm/algorithm-homework',
autoHeader: true,
subMaxLevel: 4,
auto2top: true,
markdown: {
renderer: {
code: function (code, lang) {
if (lang === "mermaid") {
return (
'<div class="mermaid">' + mermaid.render('mermaid-svg-' + num++, code) + "</div>"
);
}
return this.origin.code.apply(this, arguments);
}
}
},
plugins: [
function(hook, vm) {
hook.doneEach(function(){
//const elem = document.getElementById('gitalk-container');
//elem && (elem.innerHTML = "");
//NewGitalk().render('gitalk-container');
});
}
]
};
$(document).ready(function () {
$('pre').addClass("line-numbers").css("white-space", "pre-wrap");
})
NewGitalk()
</script>
<script src="//unpkg.com/docsify-copy-code"></script>
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-c.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-cpp.min.js"></script>
<script src="//unpkg.com/prismjs/components/prism-python.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/zoom-image.min.js"></script>
<!-- CDN files for docsify-katex -->
<script src="//cdn.jsdelivr.net/npm/docsify-katex@latest/dist/docsify-katex.js"></script>
<!-- Gitalk 配置 -->
<script src="//unpkg.com/docsify/lib/plugins/gitalk.js"></script>
<script src="//unpkg.com/gitalk/dist/gitalk.min.js"></script>
<script>
const gitalk = NewGitalk()
</script>
</body>
</html>