diff --git a/S2OJ/2021/2021.cpp b/S2OJ/2021/2021.cpp new file mode 100644 index 00000000..fdf20623 --- /dev/null +++ b/S2OJ/2021/2021.cpp @@ -0,0 +1,52 @@ +#include + +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; +} diff --git a/S2OJ/2021/data/binary1.in b/S2OJ/2021/data/binary1.in new file mode 100644 index 00000000..9d4f854b --- /dev/null +++ b/S2OJ/2021/data/binary1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4bcf7edfdf9c633a7f14fd2c0cf33aceb0e7e72d7974b9cefacf0d27461b9d87 +size 14 diff --git a/S2OJ/2021/data/binary1.out b/S2OJ/2021/data/binary1.out new file mode 100644 index 00000000..c3311138 --- /dev/null +++ b/S2OJ/2021/data/binary1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b12d9851aef9160b9c6906c34cfe7df631b44b5432a95297cc6ecc89b6c50975 +size 14 diff --git a/S2OJ/2021/data/binary2.in b/S2OJ/2021/data/binary2.in new file mode 100644 index 00000000..22f5a344 --- /dev/null +++ b/S2OJ/2021/data/binary2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:43764ea63e4d55b63710e487ba4f07a886e05eae2e74a5ec572e13c5f09f89fe +size 27 diff --git a/S2OJ/2021/data/binary2.out b/S2OJ/2021/data/binary2.out new file mode 100644 index 00000000..1f72e15a --- /dev/null +++ b/S2OJ/2021/data/binary2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:93ac18d8e3b2cd94fc707b3a34660933f503296788b35ac28a2aa270c8596ce1 +size 28 diff --git a/S2OJ/2021/data/binary3.in b/S2OJ/2021/data/binary3.in new file mode 100644 index 00000000..a65f622e --- /dev/null +++ b/S2OJ/2021/data/binary3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc23b74d609a1bed01f3c1c2fe2de5ee21acb2cf4bdc076a8d92696db78ada71 +size 36 diff --git a/S2OJ/2021/data/binary3.out b/S2OJ/2021/data/binary3.out new file mode 100644 index 00000000..7666d889 --- /dev/null +++ b/S2OJ/2021/data/binary3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb9a15fc253492d19bcd400bdb5ad9a9a746e324f3ac6ce8ad70f7c53aa21fda +size 44 diff --git a/S2OJ/2021/data/binary4.in b/S2OJ/2021/data/binary4.in new file mode 100644 index 00000000..a53c181b --- /dev/null +++ b/S2OJ/2021/data/binary4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a4d6d928d22749ee4b0a61c6919ef901a4b5f5b24fe473962372cbce4643c30 +size 46 diff --git a/S2OJ/2021/data/binary4.out b/S2OJ/2021/data/binary4.out new file mode 100644 index 00000000..f7e07503 --- /dev/null +++ b/S2OJ/2021/data/binary4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0a6df54873fdd44d88d3950b67e7f1b8dc022c1531b9d5819944359293e04ea7 +size 61 diff --git a/S2OJ/2021/data/binary5.in b/S2OJ/2021/data/binary5.in new file mode 100644 index 00000000..4533a593 --- /dev/null +++ b/S2OJ/2021/data/binary5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29d5ae8a88b6f215cbd9a1ef24736adecfeeb7a2394acace7945d4043cc4adc7 +size 53 diff --git a/S2OJ/2021/data/binary5.out b/S2OJ/2021/data/binary5.out new file mode 100644 index 00000000..81d53c59 --- /dev/null +++ b/S2OJ/2021/data/binary5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e31ad175dd5e14a1ee4d7afc5d0f385653a0d724e7f07733550167f20670f29e +size 76 diff --git a/S2OJ/2021/data/chk.cpp b/S2OJ/2021/data/chk.cpp new file mode 100644 index 00000000..677d7ab2 --- /dev/null +++ b/S2OJ/2021/data/chk.cpp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:791abe35039dbc43477c77585e5e14367ab22b3de7de15f1f0ed419776f70e10 +size 1506 diff --git a/S2OJ/2021/data/problem.conf b/S2OJ/2021/data/problem.conf new file mode 100644 index 00000000..0b16e5e0 --- /dev/null +++ b/S2OJ/2021/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e617960f3c55b7ae31aff48975b8bf919b191c72fa1057aed4cc87fc7b5e154 +size 210