From 7656d05d75afb732d6a6c623c995cdf3c6d8fec5 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Mon, 29 Sep 2025 07:33:39 +0800 Subject: [PATCH] feat: update solutions to lc problem: No.1039 --- .../README.md | 11 ++++------- .../README_EN.md | 11 ++++------- .../Solution.cpp | 7 +++---- .../Solution2.cpp | 5 ++--- .../Solution3.cpp | 5 ++--- 5 files changed, 15 insertions(+), 24 deletions(-) diff --git a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README.md b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README.md index be992f1578ac9..aa3147781d065 100644 --- a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README.md +++ b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README.md @@ -148,9 +148,8 @@ class Solution { public: int minScoreTriangulation(vector& values) { int n = values.size(); - int f[n][n]; - memset(f, 0, sizeof(f)); - function dfs = [&](int i, int j) -> int { + vector> f(n, vector(n)); + auto dfs = [&](this auto&& dfs, int i, int j) -> int { if (i + 1 == j) { return 0; } @@ -302,8 +301,7 @@ class Solution { public: int minScoreTriangulation(vector& values) { int n = values.size(); - int f[n][n]; - memset(f, 0, sizeof(f)); + vector> f(n, vector(n)); for (int i = n - 3; i >= 0; --i) { for (int j = i + 2; j < n; ++j) { f[i][j] = 1 << 30; @@ -413,8 +411,7 @@ class Solution { public: int minScoreTriangulation(vector& values) { int n = values.size(); - int f[n][n]; - memset(f, 0, sizeof(f)); + vector> f(n, vector(n)); for (int l = 3; l <= n; ++l) { for (int i = 0; i + l - 1 < n; ++i) { int j = i + l - 1; diff --git a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README_EN.md b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README_EN.md index cd7b0d350a1b9..ee6a0357d772c 100644 --- a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README_EN.md +++ b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/README_EN.md @@ -152,9 +152,8 @@ class Solution { public: int minScoreTriangulation(vector& values) { int n = values.size(); - int f[n][n]; - memset(f, 0, sizeof(f)); - function dfs = [&](int i, int j) -> int { + vector> f(n, vector(n)); + auto dfs = [&](this auto&& dfs, int i, int j) -> int { if (i + 1 == j) { return 0; } @@ -306,8 +305,7 @@ class Solution { public: int minScoreTriangulation(vector& values) { int n = values.size(); - int f[n][n]; - memset(f, 0, sizeof(f)); + vector> f(n, vector(n)); for (int i = n - 3; i >= 0; --i) { for (int j = i + 2; j < n; ++j) { f[i][j] = 1 << 30; @@ -417,8 +415,7 @@ class Solution { public: int minScoreTriangulation(vector& values) { int n = values.size(); - int f[n][n]; - memset(f, 0, sizeof(f)); + vector> f(n, vector(n)); for (int l = 3; l <= n; ++l) { for (int i = 0; i + l - 1 < n; ++i) { int j = i + l - 1; diff --git a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution.cpp b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution.cpp index b93d2f2c5d610..1400dc79c73d7 100644 --- a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution.cpp +++ b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution.cpp @@ -2,9 +2,8 @@ class Solution { public: int minScoreTriangulation(vector& values) { int n = values.size(); - int f[n][n]; - memset(f, 0, sizeof(f)); - function dfs = [&](int i, int j) -> int { + vector> f(n, vector(n)); + auto dfs = [&](this auto&& dfs, int i, int j) -> int { if (i + 1 == j) { return 0; } @@ -19,4 +18,4 @@ class Solution { }; return dfs(0, n - 1); } -}; \ No newline at end of file +}; diff --git a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution2.cpp b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution2.cpp index 23e259fe20509..2064f672c0141 100644 --- a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution2.cpp +++ b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution2.cpp @@ -2,8 +2,7 @@ class Solution { public: int minScoreTriangulation(vector& values) { int n = values.size(); - int f[n][n]; - memset(f, 0, sizeof(f)); + vector> f(n, vector(n)); for (int i = n - 3; i >= 0; --i) { for (int j = i + 2; j < n; ++j) { f[i][j] = 1 << 30; @@ -14,4 +13,4 @@ class Solution { } return f[0][n - 1]; } -}; \ No newline at end of file +}; diff --git a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution3.cpp b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution3.cpp index 2070c7c4975ec..33e69270fbb6a 100644 --- a/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution3.cpp +++ b/solution/1000-1099/1039.Minimum Score Triangulation of Polygon/Solution3.cpp @@ -2,8 +2,7 @@ class Solution { public: int minScoreTriangulation(vector& values) { int n = values.size(); - int f[n][n]; - memset(f, 0, sizeof(f)); + vector> f(n, vector(n)); for (int l = 3; l <= n; ++l) { for (int i = 0; i + l - 1 < n; ++i) { int j = i + l - 1; @@ -15,4 +14,4 @@ class Solution { } return f[0][n - 1]; } -}; \ No newline at end of file +};