Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ainevsia committed Sep 1, 2023
1 parent cb02071 commit 0c480cb
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions notes/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions notes/src/day53.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1143.最长公共子序列
25 changes: 25 additions & 0 deletions notes/src/day53/lc1035.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 1035.不相交的线

原来需要转化成‘最长公共子序列的长度’,一下子真不会

```cpp
class Solution {
public:
int maxUncrossedLines(vector<int>& v, vector<int>& w) {
// dp[i][j]:长度为[0, i - 1]的字符串text1与长度为[0, j - 1]的字符串text2的最长公共子序列为dp[i][j]
vector<vector<int>>dp(v.size()+1, vector<int>(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;
}
};
```
25 changes: 25 additions & 0 deletions notes/src/day53/lc1143.md
Original file line number Diff line number Diff line change
@@ -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<vector<int>>dp(v.size()+1, vector<int>(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;
}
};
```
20 changes: 20 additions & 0 deletions notes/src/day53/lc53.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 53. 最大子序和

自己做的 喜喜

```cpp
class Solution {
public:
int maxSubArray(vector<int>& v) {
// dp[i] 以前i个数结尾的连续子数组最大和
int res = v[0];
vector<int>dp(v.size(),0);
dp[0]=res;
for(int i=1;i<v.size();i++){
dp[i]=max(v[i],dp[i-1]+v[i]);
res=max(res,dp[i]);
}
return res;
}
};
```

0 comments on commit 0c480cb

Please sign in to comment.