mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:48:48 +00:00
Compare commits
3 Commits
aabd9221e1
...
237c953596
Author | SHA1 | Date | |
---|---|---|---|
237c953596 | |||
eef109d013 | |||
85613cc078 |
64
BZOJ/1296/1296.cpp
Normal file
64
BZOJ/1296/1296.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 55;
|
||||
|
||||
int n, m, t, f[N][N][2], g[2505];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m >> t;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int last = 0;
|
||||
std::string s;
|
||||
std::vector<std::pair<int, int>> blocks;
|
||||
|
||||
cin >> s;
|
||||
|
||||
for (int j = 0; j < m; j++) {
|
||||
if (s[j] != s[last]) {
|
||||
blocks.emplace_back(last + 1, j);
|
||||
last = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (last != m) {
|
||||
blocks.emplace_back(last + 1, m);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= blocks.size(); i++) {
|
||||
const auto &block = blocks[i - 1];
|
||||
|
||||
for (int j = blocks.size(); j; j--) {
|
||||
// 不染色时直接从前一格转移
|
||||
f[i][j][0] = std::max(f[i - 1][j][0], f[i - 1][j][1]);
|
||||
|
||||
// 刷成和上个格子一样的颜色
|
||||
f[i][j][1] = std::max(f[i - 1][j - 1][0], f[i - 1][j - 1][1]) + block.second - block.first + 1;
|
||||
|
||||
// 刷成和上上个格子一样的颜色
|
||||
if (i >= 2) {
|
||||
f[i][j][1] = std::max(f[i][j][1], f[i - 2][j][1] + block.second - block.first + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = t; j >= 0; j--) {
|
||||
for (int k = 0; k <= std::min(j, static_cast<int>(blocks.size())); k++) {
|
||||
g[j] = std::max(g[j], g[j - k] + std::max(f[blocks.size()][k][0], f[blocks.size()][k][1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << g[t] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
BZOJ/1296/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1296/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1296/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
39
Luogu/P1725/P1725.cpp
Normal file
39
Luogu/P1725/P1725.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 2e5 + 5;
|
||||
|
||||
int n, l, r, a[N << 1];
|
||||
long long f[N << 1], ans = std::numeric_limits<int>::min();
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
std::fill_n(f + 1, (N << 1) - 1, std::numeric_limits<int>::min());
|
||||
|
||||
cin >> n >> l >> r;
|
||||
|
||||
for (int i = 0; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
for (int i = l; i < n + r; i++) {
|
||||
for (int j = std::max(i - r, 0); j <= i - l; j++) {
|
||||
f[i] = std::max(f[i], f[j] + a[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = n; i < n + r; i++) {
|
||||
ans = std::max(ans, f[i]);
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
64
Luogu/P4158/P4158.cpp
Normal file
64
Luogu/P4158/P4158.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 55;
|
||||
|
||||
int n, m, t, f[N][N][2], g[2505];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m >> t;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int last = 0;
|
||||
std::string s;
|
||||
std::vector<std::pair<int, int>> blocks;
|
||||
|
||||
cin >> s;
|
||||
|
||||
for (int j = 0; j < m; j++) {
|
||||
if (s[j] != s[last]) {
|
||||
blocks.emplace_back(last + 1, j);
|
||||
last = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (last != m) {
|
||||
blocks.emplace_back(last + 1, m);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= blocks.size(); i++) {
|
||||
const auto &block = blocks[i - 1];
|
||||
|
||||
for (int j = blocks.size(); j; j--) {
|
||||
// 不染色时直接从前一格转移
|
||||
f[i][j][0] = std::max(f[i - 1][j][0], f[i - 1][j][1]);
|
||||
|
||||
// 刷成和上个格子一样的颜色
|
||||
f[i][j][1] = std::max(f[i - 1][j - 1][0], f[i - 1][j - 1][1]) + block.second - block.first + 1;
|
||||
|
||||
// 刷成和上上个格子一样的颜色
|
||||
if (i >= 2) {
|
||||
f[i][j][1] = std::max(f[i][j][1], f[i - 2][j][1] + block.second - block.first + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = t; j >= 0; j--) {
|
||||
for (int k = 0; k <= std::min(j, static_cast<int>(blocks.size())); k++) {
|
||||
g[j] = std::max(g[j], g[j - k] + std::max(f[blocks.size()][k][0], f[blocks.size()][k][1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << g[t] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user