From 0c480cb78fddda217bc8c220d5600c944dfad9cd Mon Sep 17 00:00:00 2001 From: "zhipengxu (aka. Ainevsia)" Date: Fri, 1 Sep 2023 16:51:57 +0800 Subject: [PATCH] 1 --- notes/src/SUMMARY.md | 4 ++++ notes/src/day53.md | 1 + notes/src/day53/lc1035.md | 25 +++++++++++++++++++++++++ notes/src/day53/lc1143.md | 25 +++++++++++++++++++++++++ notes/src/day53/lc53.md | 20 ++++++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 notes/src/day53.md create mode 100644 notes/src/day53/lc1035.md create mode 100644 notes/src/day53/lc1143.md create mode 100644 notes/src/day53/lc53.md diff --git a/notes/src/SUMMARY.md b/notes/src/SUMMARY.md index 6d50280..4200ec2 100644 --- a/notes/src/SUMMARY.md +++ b/notes/src/SUMMARY.md @@ -169,4 +169,8 @@ - [300.最长递增子序列](./day52/lc300.md) - [674. 最长连续递增序列](./day52/lc674.md) - [718. 最长重复子数组](./day52/lc718.md) +- [day 53](./day53.md) + - [1143.最长公共子序列](./day53/lc1143.md) + - [1035.不相交的线](./day53/lc1035.md) + - [53. 最大子序和](./day53/lc53.md) - [remains](./remains.md) \ No newline at end of file diff --git a/notes/src/day53.md b/notes/src/day53.md new file mode 100644 index 0000000..fa5b48a --- /dev/null +++ b/notes/src/day53.md @@ -0,0 +1 @@ +1143.最长公共子序列 \ No newline at end of file diff --git a/notes/src/day53/lc1035.md b/notes/src/day53/lc1035.md new file mode 100644 index 0000000..41c83a5 --- /dev/null +++ b/notes/src/day53/lc1035.md @@ -0,0 +1,25 @@ +# 1035.不相交的线 + +原来需要转化成‘最长公共子序列的长度’,一下子真不会 + +```cpp +class Solution { +public: + int maxUncrossedLines(vector& v, vector& w) { + // dp[i][j]:长度为[0, i - 1]的字符串text1与长度为[0, j - 1]的字符串text2的最长公共子序列为dp[i][j] + vector>dp(v.size()+1, vector(w.size()+1, 0)); + int result = 0; + for (int i = 1; i <= v.size(); i++) { + for (int j = 1; j <= w.size(); j++) { + if (v[i - 1] == w[j - 1]) { + dp[i][j] = dp[i - 1][j - 1] + 1; + } else { + dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); + } + if (dp[i][j] > result) result = dp[i][j]; + } + } + return result; + } +}; +``` \ No newline at end of file diff --git a/notes/src/day53/lc1143.md b/notes/src/day53/lc1143.md new file mode 100644 index 0000000..0cd0b44 --- /dev/null +++ b/notes/src/day53/lc1143.md @@ -0,0 +1,25 @@ +# 1143.最长公共子序列 + +抄了随想录 + +```cpp +class Solution { +public: + int longestCommonSubsequence(string v, string w) { + // dp[i][j]:长度为[0, i - 1]的字符串text1与长度为[0, j - 1]的字符串text2的最长公共子序列为dp[i][j] + vector>dp(v.size()+1, vector(w.size()+1, 0)); + int result = 0; + for (int i = 1; i <= v.size(); i++) { + for (int j = 1; j <= w.size(); j++) { + if (v[i - 1] == w[j - 1]) { + dp[i][j] = dp[i - 1][j - 1] + 1; + } else { + dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); + } + if (dp[i][j] > result) result = dp[i][j]; + } + } + return result; + } +}; +``` \ No newline at end of file diff --git a/notes/src/day53/lc53.md b/notes/src/day53/lc53.md new file mode 100644 index 0000000..12ddd86 --- /dev/null +++ b/notes/src/day53/lc53.md @@ -0,0 +1,20 @@ +# 53. 最大子序和 + +自己做的 喜喜 + +```cpp +class Solution { +public: + int maxSubArray(vector& v) { + // dp[i] 以前i个数结尾的连续子数组最大和 + int res = v[0]; + vectordp(v.size(),0); + dp[0]=res; + for(int i=1;i