0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 16:28:47 +00:00

#2021. 【NOIP2003 提高组】加分二叉树

https://sjzezoj.com/submission/74889
This commit is contained in:
Baoshuo Ren 2023-03-30 17:31:25 +08:00
parent e05182f7cd
commit 7a7ec4debe
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
13 changed files with 88 additions and 0 deletions

52
S2OJ/2021/2021.cpp Normal file
View File

@ -0,0 +1,52 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 35;
int n, f[N][N], root[N][N];
void dfs(int l, int r) {
if (l > r) return;
cout << root[l][r] << ' ';
if (l == r) return;
dfs(l, root[l][r] - 1);
dfs(root[l][r] + 1, r);
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> f[i][i];
f[i][i - 1] = 1;
root[i][i] = i;
}
for (int len = 2; len <= n; len++) {
for (int l = 1, r = len; r <= n; l++, r++) {
f[l][r] = f[l][l] + f[l + 1][r];
root[l][r] = l;
for (int k = l + 1; k < r; k++) {
if (f[l][r] < f[l][k - 1] * f[k + 1][r] + f[k][k]) {
f[l][r] = f[l][k - 1] * f[k + 1][r] + f[k][k];
root[l][r] = k;
}
}
}
}
cout << f[1][n] << endl;
dfs(1, n);
cout << endl;
return 0;
}

BIN
S2OJ/2021/data/binary1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/binary1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/binary2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/binary2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/binary3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/binary3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/binary4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/binary4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/binary5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/binary5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/chk.cpp (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/2021/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.