From eef109d013585d08e4cceaf8cadb24ee67fcb60e Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 8 Sep 2022 19:53:21 +0800 Subject: [PATCH] =?UTF-8?q?1296.=20[SCOI2009]=E7=B2=89=E5=88=B7=E5=8C=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://hydro.ac/d/bzoj/record/6319d7a6533abd4b31874ab4 --- BZOJ/1296/1296.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++ BZOJ/1296/data/1.in | 3 ++ BZOJ/1296/data/1.out | 3 ++ BZOJ/1296/data/10.in | 3 ++ BZOJ/1296/data/10.out | 3 ++ BZOJ/1296/data/2.in | 3 ++ BZOJ/1296/data/2.out | 3 ++ BZOJ/1296/data/3.in | 3 ++ BZOJ/1296/data/3.out | 3 ++ BZOJ/1296/data/4.in | 3 ++ BZOJ/1296/data/4.out | 3 ++ BZOJ/1296/data/5.in | 3 ++ BZOJ/1296/data/5.out | 3 ++ BZOJ/1296/data/6.in | 3 ++ BZOJ/1296/data/6.out | 3 ++ BZOJ/1296/data/7.in | 3 ++ BZOJ/1296/data/7.out | 3 ++ BZOJ/1296/data/8.in | 3 ++ BZOJ/1296/data/8.out | 3 ++ BZOJ/1296/data/9.in | 3 ++ BZOJ/1296/data/9.out | 3 ++ 21 files changed, 124 insertions(+) create mode 100644 BZOJ/1296/1296.cpp create mode 100644 BZOJ/1296/data/1.in create mode 100644 BZOJ/1296/data/1.out create mode 100644 BZOJ/1296/data/10.in create mode 100644 BZOJ/1296/data/10.out create mode 100644 BZOJ/1296/data/2.in create mode 100644 BZOJ/1296/data/2.out create mode 100644 BZOJ/1296/data/3.in create mode 100644 BZOJ/1296/data/3.out create mode 100644 BZOJ/1296/data/4.in create mode 100644 BZOJ/1296/data/4.out create mode 100644 BZOJ/1296/data/5.in create mode 100644 BZOJ/1296/data/5.out create mode 100644 BZOJ/1296/data/6.in create mode 100644 BZOJ/1296/data/6.out create mode 100644 BZOJ/1296/data/7.in create mode 100644 BZOJ/1296/data/7.out create mode 100644 BZOJ/1296/data/8.in create mode 100644 BZOJ/1296/data/8.out create mode 100644 BZOJ/1296/data/9.in create mode 100644 BZOJ/1296/data/9.out diff --git a/BZOJ/1296/1296.cpp b/BZOJ/1296/1296.cpp new file mode 100644 index 00000000..02921976 --- /dev/null +++ b/BZOJ/1296/1296.cpp @@ -0,0 +1,64 @@ +#include +#include +#include + +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> 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(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; +} diff --git a/BZOJ/1296/data/1.in b/BZOJ/1296/data/1.in new file mode 100644 index 00000000..a14176c0 --- /dev/null +++ b/BZOJ/1296/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:821d380dca2bc1118df3af2b0a2e80d7f0144c72e13ef2959d707f752c47e297 +size 119 diff --git a/BZOJ/1296/data/1.out b/BZOJ/1296/data/1.out new file mode 100644 index 00000000..1d0769d4 --- /dev/null +++ b/BZOJ/1296/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce516e29a2ccfe4bab40e4e6adab7661cd695680482c00b1faa738fc0df62698 +size 3 diff --git a/BZOJ/1296/data/10.in b/BZOJ/1296/data/10.in new file mode 100644 index 00000000..9cfbb902 --- /dev/null +++ b/BZOJ/1296/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb454cc2ee5b2fdfffe2f19348b64aa9a0e04d536acdfdd1d360be6967e50b6f +size 119 diff --git a/BZOJ/1296/data/10.out b/BZOJ/1296/data/10.out new file mode 100644 index 00000000..a196e20a --- /dev/null +++ b/BZOJ/1296/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0433e993a3dbc505d6e5cad972a1df0ab189cfe7ceece5e94fd47ca9a074370f +size 3 diff --git a/BZOJ/1296/data/2.in b/BZOJ/1296/data/2.in new file mode 100644 index 00000000..891ee528 --- /dev/null +++ b/BZOJ/1296/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ae121e4ff27fae207626150d70a4fc598baf6b089f630b9b4612371f909cb96 +size 58 diff --git a/BZOJ/1296/data/2.out b/BZOJ/1296/data/2.out new file mode 100644 index 00000000..6146a6fe --- /dev/null +++ b/BZOJ/1296/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea243e5457028e97f9bc93b37a72f8e80ea61ae081911bb037765590ee6aa435 +size 3 diff --git a/BZOJ/1296/data/3.in b/BZOJ/1296/data/3.in new file mode 100644 index 00000000..cb9e7961 --- /dev/null +++ b/BZOJ/1296/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0fe7e3ad6682a3b26e3042adb0ababb1ab5f8dd742c0dd3b04d330805d6c090b +size 2560 diff --git a/BZOJ/1296/data/3.out b/BZOJ/1296/data/3.out new file mode 100644 index 00000000..eb4590de --- /dev/null +++ b/BZOJ/1296/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2dc27d32edcc44cd288863b8edfc672abd1c61977b189f97b5813f42f5b47e7b +size 5 diff --git a/BZOJ/1296/data/4.in b/BZOJ/1296/data/4.in new file mode 100644 index 00000000..0c29dfdf --- /dev/null +++ b/BZOJ/1296/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d03948444bd588ac3bb35d79ac864b63e94eb4daefaa6b303069f52489d0b259 +size 2561 diff --git a/BZOJ/1296/data/4.out b/BZOJ/1296/data/4.out new file mode 100644 index 00000000..d0810087 --- /dev/null +++ b/BZOJ/1296/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f739882f40e2be8022d26517e0b963ab2351687845ebe1cf320efd0d0d3e388a +size 5 diff --git a/BZOJ/1296/data/5.in b/BZOJ/1296/data/5.in new file mode 100644 index 00000000..bf900312 --- /dev/null +++ b/BZOJ/1296/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e3ca4c1fe1fb295abbe5ad3c631d7fbd2d107ba4046e085a91a2fb894b7484e +size 2560 diff --git a/BZOJ/1296/data/5.out b/BZOJ/1296/data/5.out new file mode 100644 index 00000000..917459e5 --- /dev/null +++ b/BZOJ/1296/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d6c3b7325f645d3e58447f8038ba089e58a0ecfee04d680ad2860d2e994f136d +size 5 diff --git a/BZOJ/1296/data/6.in b/BZOJ/1296/data/6.in new file mode 100644 index 00000000..92911abe --- /dev/null +++ b/BZOJ/1296/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9090fa3e247cf4a3ed6566f27b5240b61e47b628329e7270ef6742365817d4f3 +size 108 diff --git a/BZOJ/1296/data/6.out b/BZOJ/1296/data/6.out new file mode 100644 index 00000000..76fbab9c --- /dev/null +++ b/BZOJ/1296/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:54183f4323f377b737433a1e98229ead0fdc686f93bab057ecb612daa94002b5 +size 3 diff --git a/BZOJ/1296/data/7.in b/BZOJ/1296/data/7.in new file mode 100644 index 00000000..1c503c41 --- /dev/null +++ b/BZOJ/1296/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5b6de25362e8bb512bb3588eb6f306cc29b74fdf61c3ffe31ee2dc096919c9b +size 2559 diff --git a/BZOJ/1296/data/7.out b/BZOJ/1296/data/7.out new file mode 100644 index 00000000..e5b940cb --- /dev/null +++ b/BZOJ/1296/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d083ddbeaf60d5039dab5b9a9f3ba47d9018019589d7d6d3172ff86d3b97a64 +size 4 diff --git a/BZOJ/1296/data/8.in b/BZOJ/1296/data/8.in new file mode 100644 index 00000000..4b9dc096 --- /dev/null +++ b/BZOJ/1296/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a53330f2c650f632838b8a036b52960b451bc430982cdb8b387b5a7dfc6e476 +size 119 diff --git a/BZOJ/1296/data/8.out b/BZOJ/1296/data/8.out new file mode 100644 index 00000000..2f3bfcde --- /dev/null +++ b/BZOJ/1296/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95cf32708a31caa478a0e9141103ac567d85e5186e697e7e0c81f75589999e31 +size 3 diff --git a/BZOJ/1296/data/9.in b/BZOJ/1296/data/9.in new file mode 100644 index 00000000..b5b02813 --- /dev/null +++ b/BZOJ/1296/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6673d2d8ad12d8c76ce0eb591a1fe505ebd2f617fda2317b4b3faf0fecbcd8b8 +size 2560 diff --git a/BZOJ/1296/data/9.out b/BZOJ/1296/data/9.out new file mode 100644 index 00000000..4a9658e1 --- /dev/null +++ b/BZOJ/1296/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:90b11c3bbb2d45739c67ce3c088d52486b699394b068e62bf35854606656679a +size 5