Skip to content

[pull] main from doocs:main #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 73 additions & 2 deletions solution/0800-0899/0808.Soup Servings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Solution {
public:
double soupServings(int n) {
double f[200][200] = {0.0};
function<double(int, int)> dfs = [&](int i, int j) -> double {
auto dfs = [&](this auto&& dfs, int i, int j) -> double {
if (i <= 0 && j <= 0) return 0.5;
if (i <= 0) return 1;
if (j <= 0) return 0;
Expand Down Expand Up @@ -205,7 +205,7 @@ func soupServings(n int) float64 {

```ts
function soupServings(n: number): number {
const f = new Array(200).fill(0).map(() => new Array(200).fill(-1));
const f = Array.from({ length: 200 }, () => Array(200).fill(-1));
const dfs = (i: number, j: number): number => {
if (i <= 0 && j <= 0) {
return 0.5;
Expand All @@ -227,6 +227,77 @@ function soupServings(n: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn soup_servings(n: i32) -> f64 {
if n > 4800 {
return 1.0;
}
Self::dfs((n + 24) / 25, (n + 24) / 25)
}

fn dfs(i: i32, j: i32) -> f64 {
static mut F: [[f64; 200]; 200] = [[0.0; 200]; 200];

unsafe {
if i <= 0 && j <= 0 {
return 0.5;
}
if i <= 0 {
return 1.0;
}
if j <= 0 {
return 0.0;
}
if F[i as usize][j as usize] > 0.0 {
return F[i as usize][j as usize];
}

let ans = 0.25 * (Self::dfs(i - 4, j) + Self::dfs(i - 3, j - 1) + Self::dfs(i - 2, j - 2) + Self::dfs(i - 1, j - 3));
F[i as usize][j as usize] = ans;
ans
}
}
}
```

#### C#

```cs
public class Solution {
private double[,] f = new double[200, 200];

public double SoupServings(int n) {
if (n > 4800) {
return 1.0;
}

return Dfs((n + 24) / 25, (n + 24) / 25);
}

private double Dfs(int i, int j) {
if (i <= 0 && j <= 0) {
return 0.5;
}
if (i <= 0) {
return 1.0;
}
if (j <= 0) {
return 0.0;
}
if (f[i, j] > 0) {
return f[i, j];
}

double ans = 0.25 * (Dfs(i - 4, j) + Dfs(i - 3, j - 1) + Dfs(i - 2, j - 2) + Dfs(i - 1, j - 3));
f[i, j] = ans;
return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
75 changes: 73 additions & 2 deletions solution/0800-0899/0808.Soup Servings/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Solution {
public:
double soupServings(int n) {
double f[200][200] = {0.0};
function<double(int, int)> dfs = [&](int i, int j) -> double {
auto dfs = [&](this auto&& dfs, int i, int j) -> double {
if (i <= 0 && j <= 0) return 0.5;
if (i <= 0) return 1;
if (j <= 0) return 0;
Expand Down Expand Up @@ -203,7 +203,7 @@ func soupServings(n int) float64 {

```ts
function soupServings(n: number): number {
const f = new Array(200).fill(0).map(() => new Array(200).fill(-1));
const f = Array.from({ length: 200 }, () => Array(200).fill(-1));
const dfs = (i: number, j: number): number => {
if (i <= 0 && j <= 0) {
return 0.5;
Expand All @@ -225,6 +225,77 @@ function soupServings(n: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn soup_servings(n: i32) -> f64 {
if n > 4800 {
return 1.0;
}
Self::dfs((n + 24) / 25, (n + 24) / 25)
}

fn dfs(i: i32, j: i32) -> f64 {
static mut F: [[f64; 200]; 200] = [[0.0; 200]; 200];

unsafe {
if i <= 0 && j <= 0 {
return 0.5;
}
if i <= 0 {
return 1.0;
}
if j <= 0 {
return 0.0;
}
if F[i as usize][j as usize] > 0.0 {
return F[i as usize][j as usize];
}

let ans = 0.25 * (Self::dfs(i - 4, j) + Self::dfs(i - 3, j - 1) + Self::dfs(i - 2, j - 2) + Self::dfs(i - 1, j - 3));
F[i as usize][j as usize] = ans;
ans
}
}
}
```

#### C#

```cs
public class Solution {
private double[,] f = new double[200, 200];

public double SoupServings(int n) {
if (n > 4800) {
return 1.0;
}

return Dfs((n + 24) / 25, (n + 24) / 25);
}

private double Dfs(int i, int j) {
if (i <= 0 && j <= 0) {
return 0.5;
}
if (i <= 0) {
return 1.0;
}
if (j <= 0) {
return 0.0;
}
if (f[i, j] > 0) {
return f[i, j];
}

double ans = 0.25 * (Dfs(i - 4, j) + Dfs(i - 3, j - 1) + Dfs(i - 2, j - 2) + Dfs(i - 1, j - 3));
f[i, j] = ans;
return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
2 changes: 1 addition & 1 deletion solution/0800-0899/0808.Soup Servings/Solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Solution {
public:
double soupServings(int n) {
double f[200][200] = {0.0};
function<double(int, int)> dfs = [&](int i, int j) -> double {
auto dfs = [&](this auto&& dfs, int i, int j) -> double {
if (i <= 0 && j <= 0) return 0.5;
if (i <= 0) return 1;
if (j <= 0) return 0;
Expand Down
30 changes: 30 additions & 0 deletions solution/0800-0899/0808.Soup Servings/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public class Solution {
private double[,] f = new double[200, 200];

public double SoupServings(int n) {
if (n > 4800) {
return 1.0;
}

return Dfs((n + 24) / 25, (n + 24) / 25);
}

private double Dfs(int i, int j) {
if (i <= 0 && j <= 0) {
return 0.5;
}
if (i <= 0) {
return 1.0;
}
if (j <= 0) {
return 0.0;
}
if (f[i, j] > 0) {
return f[i, j];
}

double ans = 0.25 * (Dfs(i - 4, j) + Dfs(i - 3, j - 1) + Dfs(i - 2, j - 2) + Dfs(i - 1, j - 3));
f[i, j] = ans;
return ans;
}
}
35 changes: 35 additions & 0 deletions solution/0800-0899/0808.Soup Servings/Solution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
impl Solution {
pub fn soup_servings(n: i32) -> f64 {
if n > 4800 {
return 1.0;
}
Self::dfs((n + 24) / 25, (n + 24) / 25)
}

fn dfs(i: i32, j: i32) -> f64 {
static mut F: [[f64; 200]; 200] = [[0.0; 200]; 200];

unsafe {
if i <= 0 && j <= 0 {
return 0.5;
}
if i <= 0 {
return 1.0;
}
if j <= 0 {
return 0.0;
}
if F[i as usize][j as usize] > 0.0 {
return F[i as usize][j as usize];
}

let ans = 0.25
* (Self::dfs(i - 4, j)
+ Self::dfs(i - 3, j - 1)
+ Self::dfs(i - 2, j - 2)
+ Self::dfs(i - 1, j - 3));
F[i as usize][j as usize] = ans;
ans
}
}
}
2 changes: 1 addition & 1 deletion solution/0800-0899/0808.Soup Servings/Solution.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function soupServings(n: number): number {
const f = new Array(200).fill(0).map(() => new Array(200).fill(-1));
const f = Array.from({ length: 200 }, () => Array(200).fill(-1));
const dfs = (i: number, j: number): number => {
if (i <= 0 && j <= 0) {
return 0.5;
Expand Down
Loading