mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 15:58:48 +00:00
4758. [USACO2017 Jan] Subsequence Reversal
https://hydro.ac/d/bzoj/record/6322a3d7bdf9bc31d1605b7c
This commit is contained in:
parent
0c3e00a97b
commit
3f348509df
57
BZOJ/4758/4758.cpp
Normal file
57
BZOJ/4758/4758.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
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;
|
||||
}
|
BIN
BZOJ/4758/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/4758/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/4758/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user