fix some typos (#1540)
Some checks failed
Dart / Dart stable on macos-latest (push) Has been cancelled
Dart / Dart stable on ubuntu-latest (push) Has been cancelled
Dart / Dart stable on windows-latest (push) Has been cancelled
.NET / .NET 8.0.x on macos-latest (push) Has been cancelled
.NET / .NET 8.0.x on ubuntu-latest (push) Has been cancelled
.NET / .NET 8.0.x on windows-latest (push) Has been cancelled
Go / Go 1.19.x on macos-latest (push) Has been cancelled
Go / Go 1.19.x on ubuntu-latest (push) Has been cancelled
Go / Go 1.19.x on windows-latest (push) Has been cancelled
Python / Python 3.10 on macos-latest (push) Has been cancelled
Python / Python 3.11 on macos-latest (push) Has been cancelled
Python / Python 3.10 on ubuntu-latest (push) Has been cancelled
Python / Python 3.11 on ubuntu-latest (push) Has been cancelled
Python / Python 3.10 on windows-latest (push) Has been cancelled
Python / Python 3.11 on windows-latest (push) Has been cancelled
Ruby / Ruby 3.3 on macos-latest (push) Has been cancelled
Ruby / Ruby 3.3 on ubuntu-latest (push) Has been cancelled
Ruby / Ruby 3.3 on windows-latest (push) Has been cancelled
Rust / build (macos-latest) (push) Has been cancelled
Rust / build (ubuntu-latest) (push) Has been cancelled
Rust / build (windows-latest) (push) Has been cancelled
Swift / Swift on macos-14 (push) Has been cancelled
Swift / Swift on ubuntu-22.04 (push) Has been cancelled

This commit is contained in:
Flamingo 2024-10-31 21:26:28 +08:00 committed by GitHub
parent b3b10f2300
commit 57cf6b1ea6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 24 additions and 24 deletions

View file

@ -105,7 +105,7 @@ public class min_path_sum {
// 暴力搜索 // 暴力搜索
int res = MinPathSumDFS(grid, n - 1, m - 1); int res = MinPathSumDFS(grid, n - 1, m - 1);
Console.WriteLine("从左上角到右下角的小路径和为 " + res); Console.WriteLine("从左上角到右下角的小路径和为 " + res);
// 记忆化搜索 // 记忆化搜索
int[][] mem = new int[n][]; int[][] mem = new int[n][];
@ -114,14 +114,14 @@ public class min_path_sum {
Array.Fill(mem[i], -1); Array.Fill(mem[i], -1);
} }
res = MinPathSumDFSMem(grid, mem, n - 1, m - 1); res = MinPathSumDFSMem(grid, mem, n - 1, m - 1);
Console.WriteLine("从左上角到右下角的小路径和为 " + res); Console.WriteLine("从左上角到右下角的小路径和为 " + res);
// 动态规划 // 动态规划
res = MinPathSumDP(grid); res = MinPathSumDP(grid);
Console.WriteLine("从左上角到右下角的小路径和为 " + res); Console.WriteLine("从左上角到右下角的小路径和为 " + res);
// 空间优化后的动态规划 // 空间优化后的动态规划
res = MinPathSumDPComp(grid); res = MinPathSumDPComp(grid);
Console.WriteLine("从左上角到右下角的小路径和为 " + res); Console.WriteLine("从左上角到右下角的小路径和为 " + res);
} }
} }

View file

@ -103,18 +103,18 @@ void main() {
// //
int res = minPathSumDFS(grid, n - 1, m - 1); int res = minPathSumDFS(grid, n - 1, m - 1);
print("从左上角到右下角的小路径和为 $res"); print("从左上角到右下角的小路径和为 $res");
// //
List<List<int>> mem = List.generate(n, (i) => List.filled(m, -1)); List<List<int>> mem = List.generate(n, (i) => List.filled(m, -1));
res = minPathSumDFSMem(grid, mem, n - 1, m - 1); res = minPathSumDFSMem(grid, mem, n - 1, m - 1);
print("从左上角到右下角的小路径和为 $res"); print("从左上角到右下角的小路径和为 $res");
// //
res = minPathSumDP(grid); res = minPathSumDP(grid);
print("从左上角到右下角的小路径和为 $res"); print("从左上角到右下角的小路径和为 $res");
// //
res = minPathSumDPComp(grid); res = minPathSumDPComp(grid);
print("从左上角到右下角的小路径和为 $res"); print("从左上角到右下角的小路径和为 $res");
} }

View file

@ -20,7 +20,7 @@ func TestMinPathSum(t *testing.T) {
// 暴力搜索 // 暴力搜索
res := minPathSumDFS(grid, n-1, m-1) res := minPathSumDFS(grid, n-1, m-1)
fmt.Printf("从左上角到右下角的小路径和为 %d\n", res) fmt.Printf("从左上角到右下角的小路径和为 %d\n", res)
// 记忆化搜索 // 记忆化搜索
mem := make([][]int, n) mem := make([][]int, n)
@ -31,13 +31,13 @@ func TestMinPathSum(t *testing.T) {
} }
} }
res = minPathSumDFSMem(grid, mem, n-1, m-1) res = minPathSumDFSMem(grid, mem, n-1, m-1)
fmt.Printf("从左上角到右下角的小路径和为 %d\n", res) fmt.Printf("从左上角到右下角的小路径和为 %d\n", res)
// 动态规划 // 动态规划
res = minPathSumDP(grid) res = minPathSumDP(grid)
fmt.Printf("从左上角到右下角的小路径和为 %d\n", res) fmt.Printf("从左上角到右下角的小路径和为 %d\n", res)
// 空间优化后的动态规划 // 空间优化后的动态规划
res = minPathSumDPComp(grid) res = minPathSumDPComp(grid)
fmt.Printf("从左上角到右下角的小路径和为 %d\n", res) fmt.Printf("从左上角到右下角的小路径和为 %d\n", res)
} }

View file

@ -88,17 +88,17 @@ if __name__ == "__main__":
# 暴力搜索 # 暴力搜索
res = min_path_sum_dfs(grid, n - 1, m - 1) res = min_path_sum_dfs(grid, n - 1, m - 1)
print(f"从左上角到右下角的小路径和为 {res}") print(f"从左上角到右下角的小路径和为 {res}")
# 记忆化搜索 # 记忆化搜索
mem = [[-1] * m for _ in range(n)] mem = [[-1] * m for _ in range(n)]
res = min_path_sum_dfs_mem(grid, mem, n - 1, m - 1) res = min_path_sum_dfs_mem(grid, mem, n - 1, m - 1)
print(f"从左上角到右下角的小路径和为 {res}") print(f"从左上角到右下角的小路径和为 {res}")
# 动态规划 # 动态规划
res = min_path_sum_dp(grid) res = min_path_sum_dp(grid)
print(f"从左上角到右下角的小路径和为 {res}") print(f"从左上角到右下角的小路径和为 {res}")
# 空间优化后的动态规划 # 空间优化后的动态规划
res = min_path_sum_dp_comp(grid) res = min_path_sum_dp_comp(grid)
print(f"从左上角到右下角的小路径和为 {res}") print(f"从左上角到右下角的小路径和为 {res}")

View file

@ -76,18 +76,18 @@ if __FILE__ == $0
# 暴力搜索 # 暴力搜索
res = min_path_sum_dfs(grid, n - 1, m - 1) res = min_path_sum_dfs(grid, n - 1, m - 1)
puts "从左上角到右下角的小路径和为 #{res}" puts "从左上角到右下角的小路径和为 #{res}"
# 记忆化搜索 # 记忆化搜索
mem = Array.new(n) { Array.new(m, - 1) } mem = Array.new(n) { Array.new(m, - 1) }
res = min_path_sum_dfs_mem(grid, mem, n - 1, m -1) res = min_path_sum_dfs_mem(grid, mem, n - 1, m -1)
puts "从左上角到右下角的小路径和为 #{res}" puts "从左上角到右下角的小路径和为 #{res}"
# 动态规划 # 动态规划
res = min_path_sum_dp(grid) res = min_path_sum_dp(grid)
puts "从左上角到右下角的小路径和为 #{res}" puts "从左上角到右下角的小路径和为 #{res}"
# 空间优化后的动态规划 # 空间优化后的动态规划
res = min_path_sum_dp_comp(grid) res = min_path_sum_dp_comp(grid)
puts "从左上角到右下角的小路径和为 #{res}" puts "从左上角到右下角的小路径和为 #{res}"
end end

View file

@ -105,19 +105,19 @@ enum MinPathSum {
// //
var res = minPathSumDFS(grid: grid, i: n - 1, j: m - 1) var res = minPathSumDFS(grid: grid, i: n - 1, j: m - 1)
print("从左上角到右下角的小路径和为 \(res)") print("从左上角到右下角的小路径和为 \(res)")
// //
var mem = Array(repeating: Array(repeating: -1, count: m), count: n) var mem = Array(repeating: Array(repeating: -1, count: m), count: n)
res = minPathSumDFSMem(grid: grid, mem: &mem, i: n - 1, j: m - 1) res = minPathSumDFSMem(grid: grid, mem: &mem, i: n - 1, j: m - 1)
print("从左上角到右下角的小路径和为 \(res)") print("从左上角到右下角的小路径和为 \(res)")
// //
res = minPathSumDP(grid: grid) res = minPathSumDP(grid: grid)
print("从左上角到右下角的小路径和为 \(res)") print("从左上角到右下角的小路径和为 \(res)")
// //
res = minPathSumDPComp(grid: grid) res = minPathSumDPComp(grid: grid)
print("从左上角到右下角的小路径和为 \(res)") print("从左上角到右下角的小路径和为 \(res)")
} }
} }