feat(csharp) .NET 8.0 code migration (#966)

* .net 8.0 migration

* update docs

* revert change

* revert change and update appendix docs

* remove static

* Update binary_search_insertion.cs

* Update binary_search_insertion.cs

* Update binary_search_edge.cs

* Update binary_search_insertion.cs

* Update binary_search_edge.cs

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
hpstory
2023-11-26 23:18:44 +08:00
committed by GitHub
parent d960c99a1f
commit 56b20eff36
93 changed files with 539 additions and 487 deletions

View File

@@ -8,7 +8,7 @@ namespace hello_algo.chapter_dynamic_programming;
public class knapsack {
/* 0-1 背包:暴力搜索 */
public int KnapsackDFS(int[] weight, int[] val, int i, int c) {
int KnapsackDFS(int[] weight, int[] val, int i, int c) {
// 若已选完所有物品或背包无容量,则返回价值 0
if (i == 0 || c == 0) {
return 0;
@@ -25,7 +25,7 @@ public class knapsack {
}
/* 0-1 背包:记忆化搜索 */
public int KnapsackDFSMem(int[] weight, int[] val, int[][] mem, int i, int c) {
int KnapsackDFSMem(int[] weight, int[] val, int[][] mem, int i, int c) {
// 若已选完所有物品或背包无容量,则返回价值 0
if (i == 0 || c == 0) {
return 0;
@@ -47,7 +47,7 @@ public class knapsack {
}
/* 0-1 背包:动态规划 */
public int KnapsackDP(int[] weight, int[] val, int cap) {
int KnapsackDP(int[] weight, int[] val, int cap) {
int n = weight.Length;
// 初始化 dp 表
int[,] dp = new int[n + 1, cap + 1];
@@ -67,7 +67,7 @@ public class knapsack {
}
/* 0-1 背包:空间优化后的动态规划 */
public int KnapsackDPComp(int[] weight, int[] val, int cap) {
int KnapsackDPComp(int[] weight, int[] val, int cap) {
int n = weight.Length;
// 初始化 dp 表
int[] dp = new int[cap + 1];
@@ -89,8 +89,8 @@ public class knapsack {
[Test]
public void Test() {
int[] weight = { 10, 20, 30, 40, 50 };
int[] val = { 50, 120, 150, 210, 240 };
int[] weight = [10, 20, 30, 40, 50];
int[] val = [50, 120, 150, 210, 240];
int cap = 50;
int n = weight.Length;