diff --git a/BZOJ/4758/4758.cpp b/BZOJ/4758/4758.cpp new file mode 100644 index 00000000..a756fdad --- /dev/null +++ b/BZOJ/4758/4758.cpp @@ -0,0 +1,57 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 55; + +int n, a[N], f[N][N][N][N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + for (int l = 1; l <= n; l++) { + for (int i = 1; i <= a[l]; i++) { + for (int j = a[l]; j <= 50; j++) { + f[l][l][i][j] = 1; + } + } + } + + for (int len = 2; len <= n; len++) { + for (int l = 1, r = len; r <= n; l++, r++) { + for (int i = 1; i <= 50; i++) { + for (int j = i; j <= 50; j++) { + f[l][r][i][j] = std::max({ + f[l][r][i][j], + f[l + 1][r][i][j] + (a[l] == i), + f[l][r - 1][i][j] + (a[r] == j), + f[l + 1][r - 1][i][j] + (a[r] == i) + (a[l] == j), + }); + + f[l][r][i][j + 1] = std::max(f[l][r][i][j + 1], f[l][r][i][j]); + f[l][r][i - 1][j] = std::max(f[l][r][i - 1][j], f[l][r][i][j]); + } + } + + for (int j = 1; j <= 50; j++) { + for (int i = j; i; i--) { + f[l][r][i - 1][j] = std::max(f[l][r][i - 1][j], f[l][r][i][j]); + } + } + } + } + + cout << f[1][n][1][50] << endl; + + return 0; +} diff --git a/BZOJ/4758/data/1.in b/BZOJ/4758/data/1.in new file mode 100644 index 00000000..6b38c9e3 --- /dev/null +++ b/BZOJ/4758/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3632b1562858f7cb46d52df09d0b72f9ac7e1222a41d312950a161469f88fcf +size 60 diff --git a/BZOJ/4758/data/1.out b/BZOJ/4758/data/1.out new file mode 100644 index 00000000..f4808fee --- /dev/null +++ b/BZOJ/4758/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:917df3320d778ddbaa5c5c7742bc4046bf803c36ed2b050f30844ed206783469 +size 3 diff --git a/BZOJ/4758/data/10.in b/BZOJ/4758/data/10.in new file mode 100644 index 00000000..e9472869 --- /dev/null +++ b/BZOJ/4758/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b612d789398d77cabbfaf3a1c9d3ba26a49e2bf052eb184268700a2e6b71877 +size 12 diff --git a/BZOJ/4758/data/10.out b/BZOJ/4758/data/10.out new file mode 100644 index 00000000..d76a596d --- /dev/null +++ b/BZOJ/4758/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0b5c2c2211c8d67ed15e75e656c7862d086e9245420892a7de62cd9ec582a06 +size 2 diff --git a/BZOJ/4758/data/2.in b/BZOJ/4758/data/2.in new file mode 100644 index 00000000..83b2e6e7 --- /dev/null +++ b/BZOJ/4758/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6050a9baf324f2bd28910785b55d3e2f09c987cb52edfe2b5d42950eca4c9ed +size 145 diff --git a/BZOJ/4758/data/2.out b/BZOJ/4758/data/2.out new file mode 100644 index 00000000..8962e2ae --- /dev/null +++ b/BZOJ/4758/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e2ae11dad0616f66bbb2b6e6556f580bb987fd911d7132aa6bee2bfc7cc7b52 +size 3 diff --git a/BZOJ/4758/data/3.in b/BZOJ/4758/data/3.in new file mode 100644 index 00000000..2a40ff1f --- /dev/null +++ b/BZOJ/4758/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82cb939e977369cff14b88217d047ed2b447a5716b96dbdc7a3d74b030084203 +size 130 diff --git a/BZOJ/4758/data/3.out b/BZOJ/4758/data/3.out new file mode 100644 index 00000000..0becde63 --- /dev/null +++ b/BZOJ/4758/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5378796307535df3ec8d8b15a2e2dc5641419c3d3060cfe32238c0fa973f7aa3 +size 3 diff --git a/BZOJ/4758/data/4.in b/BZOJ/4758/data/4.in new file mode 100644 index 00000000..8132e7a7 --- /dev/null +++ b/BZOJ/4758/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6913b394c28540b185dae8054c84ce9683239f37a135308bb2bbf90aae3650a9 +size 33 diff --git a/BZOJ/4758/data/4.out b/BZOJ/4758/data/4.out new file mode 100644 index 00000000..f2baf931 --- /dev/null +++ b/BZOJ/4758/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10159baf262b43a92d95db59dae1f72c645127301661e0a3ce4e38b295a97c58 +size 2 diff --git a/BZOJ/4758/data/5.in b/BZOJ/4758/data/5.in new file mode 100644 index 00000000..1e6f2acc --- /dev/null +++ b/BZOJ/4758/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:76723c6f6b3e08c7f6e12f5a193a67d0e0a05600da68024f9e6daa5051453034 +size 115 diff --git a/BZOJ/4758/data/5.out b/BZOJ/4758/data/5.out new file mode 100644 index 00000000..76fbab9c --- /dev/null +++ b/BZOJ/4758/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:54183f4323f377b737433a1e98229ead0fdc686f93bab057ecb612daa94002b5 +size 3 diff --git a/BZOJ/4758/data/6.in b/BZOJ/4758/data/6.in new file mode 100644 index 00000000..070708a6 --- /dev/null +++ b/BZOJ/4758/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b8efb4a24edd863910be48e21d6f65a1ae2b6493a3292adf5cc02a8ac12fa571 +size 48 diff --git a/BZOJ/4758/data/6.out b/BZOJ/4758/data/6.out new file mode 100644 index 00000000..d790bd49 --- /dev/null +++ b/BZOJ/4758/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e6d31a5983a91251bfae5aefa1c0a19d8ba3cf601d0e8a706b4cfa9661a6b8a +size 2 diff --git a/BZOJ/4758/data/7.in b/BZOJ/4758/data/7.in new file mode 100644 index 00000000..9e00a603 --- /dev/null +++ b/BZOJ/4758/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:856fdc6e0fb4a2c71c61c3a0de7caa5b9aff1f10ddc7eb37e109dcea902b78cd +size 20 diff --git a/BZOJ/4758/data/7.out b/BZOJ/4758/data/7.out new file mode 100644 index 00000000..d790bd49 --- /dev/null +++ b/BZOJ/4758/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e6d31a5983a91251bfae5aefa1c0a19d8ba3cf601d0e8a706b4cfa9661a6b8a +size 2 diff --git a/BZOJ/4758/data/8.in b/BZOJ/4758/data/8.in new file mode 100644 index 00000000..18828530 --- /dev/null +++ b/BZOJ/4758/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f4e7227076d4c0ada20a9131ec1940587c9bdfead2187b4118da949bbe1f6e6 +size 89 diff --git a/BZOJ/4758/data/8.out b/BZOJ/4758/data/8.out new file mode 100644 index 00000000..51b03484 --- /dev/null +++ b/BZOJ/4758/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a92adbc0cee38ef658c71ce1b1bf8c65668f166bfb213644c895ccb1ad07a25 +size 3 diff --git a/BZOJ/4758/data/9.in b/BZOJ/4758/data/9.in new file mode 100644 index 00000000..3cf9befa --- /dev/null +++ b/BZOJ/4758/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9bfe8d3591c3b4b1a6163aa3d474f4bf9af805f60bd91306f10a5bdabede3673 +size 101 diff --git a/BZOJ/4758/data/9.out b/BZOJ/4758/data/9.out new file mode 100644 index 00000000..2ccf849a --- /dev/null +++ b/BZOJ/4758/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:238903180cc104ec2c5d8b3f20c5bc61b389ec0a967df8cc208cdc7cd454174f +size 3