From b6c8c0341178bb1be7d4ded4c4df4aac2ff7f714 Mon Sep 17 00:00:00 2001 From: wolves Date: Tue, 14 Oct 2025 19:34:49 +0800 Subject: [PATCH] 251013 --- 25/09/3005.java | 5 ++++ 25/10/ds3.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 25/10/ds3.cpp diff --git a/25/09/3005.java b/25/09/3005.java index fef91ae..c74dd83 100644 --- a/25/09/3005.java +++ b/25/09/3005.java @@ -17,4 +17,9 @@ class Solution { } return ans; } + + public static void main(String[] args) { + Solution s = new Solution(); + System.out.println(s.maxFrequencyElements(new int[] {1, 2, 3, 4, 5})); + } } \ No newline at end of file diff --git a/25/10/ds3.cpp b/25/10/ds3.cpp new file mode 100644 index 0000000..77e97cd --- /dev/null +++ b/25/10/ds3.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +using namespace std; + +// 方法1: 生成特定的二维vector +static vector> generateSpecificMatrix() +{ + return { + {2, 3, 4, 2, 5}, + {6, 2, 3, 1, 8}, + {3, 5, 4, 6, 4}, + {4, 2, 3, 2, 3}, + {2, 1, 6, 7, 5}}; +} + +// 方法2: 生成随机n×n数组 +vector> generateRandomMatrix(int n, int min_val = 1, int max_val = 10) +{ + random_device rd; + mt19937 gen(rd()); + uniform_int_distribution dis(min_val, max_val); + + vector> matrix(n, vector(n)); + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + matrix[i][j] = dis(gen); + } + } + return matrix; +} + +// 打印矩阵的辅助函数 +void printMatrix(const vector> &matrix) +{ + for (const auto &row : matrix) + { + for (int val : row) + { + cout << setw(3) << val << " "; + } + cout << endl; + } + cout << endl; +} + +int getMaxWay(std::vector> matrix) +{ + int n = matrix.size(); + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + matrix[i][j] += max(i - 1 >= 0 ? matrix[i - 1][j] : 0, j - 1 >= 0 ? matrix[i][j - 1] : 0); + } + } + printMatrix(matrix); + return matrix[n - 1][n - 1]; +} + +int main() +{ + auto matrix = generateSpecificMatrix(); + printMatrix(matrix); + std::cout << getMaxWay(matrix); + return 0; +}