mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 17:08:48 +00:00
parent
e05182f7cd
commit
7a7ec4debe
52
S2OJ/2021/2021.cpp
Normal file
52
S2OJ/2021/2021.cpp
Normal 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
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
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
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
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
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
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
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
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
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
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
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
BIN
S2OJ/2021/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user