WIP Initral

This commit is contained in:
Hmtsai 2024-07-09 14:29:33 +08:00
commit ce649523f8
5 changed files with 163 additions and 0 deletions

28
.vscode/tasks.json vendored Normal file
View File

@ -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"
}

41
ssoier/1281/1281.cpp Normal file
View File

@ -0,0 +1,41 @@
// ID:1281 TITLE:最大上升子序列
#include <iostream>
#include <vector>
int main() {
int length;
std::cin >> length;
std::vector<int> v(length);
std::vector<std::vector<int>> 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>());
}
}
}
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;
}

View File

@ -0,0 +1,30 @@
// ID:1281 TITLE:最大上升子序列
#include <iostream>
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][]
}
}
}
}

30
ssoier/1281/README.md Normal file
View File

@ -0,0 +1,30 @@
# 1281最长上升子序列
## 题目描述
一个数的序列 $b_i$ ,当$b1<b2<...<bS$的时候我们称这个序列是上升的对于给定的一个序列(a1,a2,...,aN)我们可以得到一些上升的子序列$a_{i1},a_{i2},...,a_{iK}$这里 $1i1<i2<...<iKN$比如对于序列$1,7,3,5,9,4,8$有它的一些上升子序列$(1,7),(3,4,8)$等等这些子序列中最长的长度是 4比如子序列$(1,3,5,8)$
你的任务,就是对于给定的序列,求出最长上升子序列的长度。
## 输入
输入的第一行是序列的长度 N(1≤N≤1000)。第二行给出序列中的 N 个整数,这些整数的取值范围都在 0 到 10000。
## 输出
最长上升子序列的长度。
## 样例
### 输入
```text
7
1 7 3 5 9 4 8
```
### 输出
```text
4
```

34
ssoier/1285.cpp Normal file
View File

@ -0,0 +1,34 @@
// ID:1285 TITLE:最大上升子序列和
#include <iostream>
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;
}