From 228992183311ffb4d29ef669780da3ee49d6f256 Mon Sep 17 00:00:00 2001 From: MH Hung Date: Tue, 12 Aug 2025 10:49:05 +0800 Subject: [PATCH 1/2] feat : add C# solution --- 202508/2787 numberOfWays/C#/C#.sln | 24 ++++++++++ 202508/2787 numberOfWays/C#/Program.cs | 48 +++++++++++++++++++ .../2787 numberOfWays/C#/numberOfWays.csproj | 10 ++++ 3 files changed, 82 insertions(+) create mode 100644 202508/2787 numberOfWays/C#/C#.sln create mode 100644 202508/2787 numberOfWays/C#/Program.cs create mode 100644 202508/2787 numberOfWays/C#/numberOfWays.csproj diff --git a/202508/2787 numberOfWays/C#/C#.sln b/202508/2787 numberOfWays/C#/C#.sln new file mode 100644 index 0000000..7fd954e --- /dev/null +++ b/202508/2787 numberOfWays/C#/C#.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}") = "numberOfWays", "numberOfWays.csproj", "{1E81E272-AF2C-9CB4-F90B-0AAC263D10DC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1E81E272-AF2C-9CB4-F90B-0AAC263D10DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E81E272-AF2C-9CB4-F90B-0AAC263D10DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E81E272-AF2C-9CB4-F90B-0AAC263D10DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E81E272-AF2C-9CB4-F90B-0AAC263D10DC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AD18FC84-E2FB-4382-96DF-8AE7E50C1401} + EndGlobalSection +EndGlobal diff --git a/202508/2787 numberOfWays/C#/Program.cs b/202508/2787 numberOfWays/C#/Program.cs new file mode 100644 index 0000000..9f51042 --- /dev/null +++ b/202508/2787 numberOfWays/C#/Program.cs @@ -0,0 +1,48 @@ +// knapsack problem +public class Solution +{ + public int NumberOfWays(int n, int x) + { + const int MOD = 1_000_000_007; + // list all the powers which smaller than n + var powers = new List(); + var num = 1; + + while (true) + { + int pow = (int)Math.Pow(num, x); + if (pow > n) + break; + powers.Add(pow); + num++; + } + + // dynamic programming + var dp = new int[n + 1]; + dp[0] = 1; + + foreach (var power in powers) + { + for (var i = n; i >= power; i--) + { + dp[i] = (dp[i] + dp[i - power]) % MOD; + } + } + + return dp[n]; + + } + +} + +class Program +{ + static void Main() + { + var solution = new Solution(); + + Console.WriteLine(solution.NumberOfWays(4, 1)); + Console.WriteLine(solution.NumberOfWays(100, 3)); + + } +} \ No newline at end of file diff --git a/202508/2787 numberOfWays/C#/numberOfWays.csproj b/202508/2787 numberOfWays/C#/numberOfWays.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/202508/2787 numberOfWays/C#/numberOfWays.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + From c31ff3820d9b9e4a9ab9db8cba3cf50c4064a385 Mon Sep 17 00:00:00 2001 From: MH Hung Date: Tue, 12 Aug 2025 15:56:55 +0800 Subject: [PATCH 2/2] feat : change account --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b019fa..ba7ea24 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # coding-practice Practice from Daily Leetcode -ACC : bqq43498@toaik.com +ACC : iak64825@jioso.com Password : ww5&Hy73dgh \ No newline at end of file