diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..31db540 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/bin +**/obj \ No newline at end of file diff --git a/202508/3363 MaxCollectedFruits/C#/MaxCollectedFruits.csproj b/202508/3363 MaxCollectedFruits/C#/MaxCollectedFruits.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/202508/3363 MaxCollectedFruits/C#/MaxCollectedFruits.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/202508/3363 MaxCollectedFruits/C#/MaxCollectedFruits.sln b/202508/3363 MaxCollectedFruits/C#/MaxCollectedFruits.sln new file mode 100644 index 0000000..e5f8bd0 --- /dev/null +++ b/202508/3363 MaxCollectedFruits/C#/MaxCollectedFruits.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaxCollectedFruits", "MaxCollectedFruits.csproj", "{AA67CF61-67B3-7229-E3F9-D471B0EF4EDE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AA67CF61-67B3-7229-E3F9-D471B0EF4EDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA67CF61-67B3-7229-E3F9-D471B0EF4EDE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA67CF61-67B3-7229-E3F9-D471B0EF4EDE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA67CF61-67B3-7229-E3F9-D471B0EF4EDE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B9D47F51-61C3-4A24-890A-01C9AC85EC93} + EndGlobalSection +EndGlobal diff --git a/202508/3363 MaxCollectedFruits/C#/Program.cs b/202508/3363 MaxCollectedFruits/C#/Program.cs new file mode 100644 index 0000000..3824bef --- /dev/null +++ b/202508/3363 MaxCollectedFruits/C#/Program.cs @@ -0,0 +1,67 @@ +public class Solution +{ + public int MaxCollectedFruits(int[][] fruits) + { + int n = fruits.Length; + int ans = 0; + for (int i = 0; i < n; ++i) ans += fruits[i][i]; + + int dp() + { + int[] prev = Enumerable.Repeat(int.MinValue, n).ToArray(); + int[] curr = new int[n]; + prev[n - 1] = fruits[0][n - 1]; + for (int i = 1; i < n - 1; ++i) + { + Array.Fill(curr, int.MinValue); + for (int j = Math.Max(n - 1 - i, i + 1); j < n; ++j) + { + int best = prev[j]; + if (j - 1 >= 0) + { + best = Math.Max(best, prev[j - 1]); + } + if (j + 1 < n) + { + best = Math.Max(best, prev[j + 1]); + } + curr[j] = best + fruits[i][j]; + } + var temp = prev; + prev = curr; + curr = temp; + } + return prev[n - 1]; + } + + ans += dp(); + + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < i; ++j) + { + var temp = fruits[j][i]; + fruits[j][i] = fruits[i][j]; + fruits[i][j] = temp; + } + } + + ans += dp(); + return ans; + } + + +} + + +class Program +{ + static void Main() + { + var Solution = new Solution(); + + var fruits = new int[][] { [1,2,3,4],[5,6,8,7],[9,10,11,12],[13,14,15,16]}; + + Console.WriteLine(Solution.MaxCollectedFruits(fruits)); + } +} \ No newline at end of file diff --git a/Note/Dynamic Programming.md b/Note/Dynamic Programming.md new file mode 100644 index 0000000..138982d --- /dev/null +++ b/Note/Dynamic Programming.md @@ -0,0 +1,4 @@ +# Dynamic programming 動態規劃 + +## 2D +https://hackmd.io/@bangyewu/By3RWr0ZT \ No newline at end of file diff --git a/README.md b/README.md index f62596d..5b019fa 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # coding-practice -Practice from Daily Leetcode \ No newline at end of file +Practice from Daily Leetcode +ACC : bqq43498@toaik.com +Password : ww5&Hy73dgh \ No newline at end of file