refactor: refactor project structure

This commit is contained in:
2025-09-01 09:13:32 +08:00
parent 524784a3c5
commit 9fec047d3f
42 changed files with 0 additions and 4 deletions

View File

@@ -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}") = "soupServings", "soupServings.csproj", "{6D960F00-6A53-6E19-86A1-4BF3D1CD764F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6D960F00-6A53-6E19-86A1-4BF3D1CD764F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D960F00-6A53-6E19-86A1-4BF3D1CD764F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D960F00-6A53-6E19-86A1-4BF3D1CD764F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D960F00-6A53-6E19-86A1-4BF3D1CD764F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {11CC27B7-C17E-4820-8A68-ADD32A2B37F8}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,56 @@
using System;
public class Solution
{
private Dictionary<(int, int), double> dp = new Dictionary<(int, int), double>();
public double SoupServings(int n)
{
if (n > 5000)
return 1.0;
n = (n + 24) / 25;
// use dynamic programming
return Helper(n, n);
}
private double Helper(int a, int b)
{
if (a <= 0 && b <= 0)
{
return 0.5;
}
if (a <= 0)
{
return 1.0;
}
if (b <= 0)
{
return 0.0;
}
if (dp.ContainsKey((a, b)))
{
return dp[(a, b)];
}
double probability = 0.25 * (
Helper(a - 4, b) +
Helper(a - 3, b - 1) +
Helper(a - 2, b - 2) +
Helper(a - 1, b - 3)
);
dp[(a, b)] = probability;
return probability;
}
}
class Program
{
static void Main()
{
var Solution = new Solution();
var ans = Solution.SoupServings(800);
Console.WriteLine(ans);
}
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>