From ce649523f8dae37ed7909fdef3f9bffd7f0b934f Mon Sep 17 00:00:00 2001 From: hmtsai Date: Tue, 9 Jul 2024 14:29:33 +0800 Subject: [PATCH] WIP Initral --- .vscode/tasks.json | 28 +++++++++++++++++++++++++ ssoier/1281/1281.cpp | 41 +++++++++++++++++++++++++++++++++++++ ssoier/1281/1281_remade.cpp | 30 +++++++++++++++++++++++++++ ssoier/1281/README.md | 30 +++++++++++++++++++++++++++ ssoier/1285.cpp | 34 ++++++++++++++++++++++++++++++ 5 files changed, 163 insertions(+) create mode 100644 .vscode/tasks.json create mode 100644 ssoier/1281/1281.cpp create mode 100644 ssoier/1281/1281_remade.cpp create mode 100644 ssoier/1281/README.md create mode 100644 ssoier/1285.cpp diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..cb8b75d --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++ 生成活动文件", + "command": "/usr/bin/g++", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "调试器生成的任务。" + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/ssoier/1281/1281.cpp b/ssoier/1281/1281.cpp new file mode 100644 index 0000000..4b8c9d4 --- /dev/null +++ b/ssoier/1281/1281.cpp @@ -0,0 +1,41 @@ +// ID:1281 TITLE:最大上升子序列 + +#include +#include + +int main() { + int length; + std::cin >> length; + std::vector v(length); + std::vector> result; + for (int i = 0; i < length; i++) { + int input_element; + std::cin >> input_element; + v[i] = input_element; + } + { + bool flag = true; + int prev = 0; + while (!v.empty()) { + if (*v.rbegin() > prev) { + prev = *v.rbegin(); + v.pop_back(); + result.end()->push_back(prev); + } else { + flag = false; + result.push_back(std::vector()); + } + } + } + int max = 0, max_index = 0; + for (int i = 0; i < result.size(); i++) { + if (result[i].size() > max) { + max_index = i; + max = result[i].size(); + } + } + for (auto v : result[max_index]) { + std::cout << v << " "; + } + std::cout << std::endl; +} \ No newline at end of file diff --git a/ssoier/1281/1281_remade.cpp b/ssoier/1281/1281_remade.cpp new file mode 100644 index 0000000..04a304c --- /dev/null +++ b/ssoier/1281/1281_remade.cpp @@ -0,0 +1,30 @@ +// ID:1281 TITLE:最大上升子序列 + +#include + +int main() +{ + int length; + std::cin >> length; + int v[length], v_size = length - 1; + int result[100][length], result_num = 0; + for (int i = 0; i < length; i++) + { + int input_element; + std::cin >> input_element; + v[i] = input_element; + } + { + bool flag = true; + int prev = 0; + while (v_size != 0) + { + if (v[v_size] > prev) + { + prev = v[v_size]; + v_size--; + result[result_num][] + } + } + } +} \ No newline at end of file diff --git a/ssoier/1281/README.md b/ssoier/1281/README.md new file mode 100644 index 0000000..9115d9f --- /dev/null +++ b/ssoier/1281/README.md @@ -0,0 +1,30 @@ +# 1281:最长上升子序列 + +## 题目描述 + +一个数的序列 $b_i$ ,当$b1 + +const int MAX = 1001; + +int main() +{ + int n, a[1001], b[1001], total = -1; + std::cin >> n; + for (int i = 1; i <= n; i++) + { + std::cin >> a[i]; + b[i] = a[i]; + } + for (int i = 0; i <= n; i++) + { + for (int j = 0; j < i; j++) + { + if (a[i] > a[j]) + { + if (a[i] > a[j]) + { + b[i] = std::max(b[i], b[j] + a[i]); + } + } + } + } + for (int i = 1; i <= n; i++) + { + total = std::max(total, b[i]); + } + std::cout << total; +} \ No newline at end of file