From 58b85e4ba47a24c48e720167fbd8e96668236582 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 15 Sep 2022 12:39:28 +0800 Subject: [PATCH] 3928. [CERC2014] Outer space invaders https://hydro.ac/d/bzoj/record/6322ac7bbdf9bc31d1606151 --- BZOJ/3928/3928.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++ BZOJ/3928/data/1.in | 3 ++ BZOJ/3928/data/1.out | 3 ++ BZOJ/3928/data/2.in | 3 ++ BZOJ/3928/data/2.out | 3 ++ 5 files changed, 95 insertions(+) create mode 100644 BZOJ/3928/3928.cpp create mode 100644 BZOJ/3928/data/1.in create mode 100644 BZOJ/3928/data/1.out create mode 100644 BZOJ/3928/data/2.in create mode 100644 BZOJ/3928/data/2.out diff --git a/BZOJ/3928/3928.cpp b/BZOJ/3928/3928.cpp new file mode 100644 index 00000000..f44b1e5a --- /dev/null +++ b/BZOJ/3928/3928.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 305; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + + cin >> t; + + while (t--) { + int n; + + cin >> n; + + std::vector> data(n); + std::vector nums; + + for (auto& e : data) { + int a, b, d; + + cin >> a >> b >> d; + + e = std::make_tuple(a, b, d); + nums.emplace_back(a); + nums.emplace_back(b); + } + + std::sort(nums.begin(), nums.end()); + nums.erase(std::unique(nums.begin(), nums.end()), nums.end()); + + for (auto& e : data) { + std::get<0>(e) = std::lower_bound(nums.begin(), nums.end(), std::get<0>(e)) - nums.begin() + 1; + std::get<1>(e) = std::lower_bound(nums.begin(), nums.end(), std::get<1>(e)) - nums.begin() + 1; + } + + int m = nums.size(); + std::array, N << 1> f; + + for (int len = 0; len < m; len++) { + for (int l = 1, r = 1 + len; r <= m; l++, r++) { + auto it = data.end(); + + for (auto _it = data.begin(); _it != data.end(); _it++) { + int a, b, d; + std::tie(a, b, d) = *_it; + + if (l <= a && b <= r && (it == data.end() || d > std::get<2>(*it))) { + it = _it; + } + } + + if (it == data.end()) { + f[l][r] = 0; + } else { + f[l][r] = std::numeric_limits::max(); + + int a, b, d; + std::tie(a, b, d) = *it; + + for (int i = a; i <= b; i++) { + f[l][r] = std::min(f[l][r], f[l][i - 1] + d + f[i + 1][r]); + } + } + } + } + + cout << f[1][m] << endl; + } + + return 0; +} diff --git a/BZOJ/3928/data/1.in b/BZOJ/3928/data/1.in new file mode 100644 index 00000000..6965783f --- /dev/null +++ b/BZOJ/3928/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c99fcff5a75ae63f0fcc2e4469086bbefd5c27fe578212aa1ad2b41a1163d870 +size 77371 diff --git a/BZOJ/3928/data/1.out b/BZOJ/3928/data/1.out new file mode 100644 index 00000000..cb3e3357 --- /dev/null +++ b/BZOJ/3928/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0dbec2ac78d080555e787248e1e7f5c841d3285cdffa3f7ebb54fcb8093d6f9 +size 1015 diff --git a/BZOJ/3928/data/2.in b/BZOJ/3928/data/2.in new file mode 100644 index 00000000..01d44197 --- /dev/null +++ b/BZOJ/3928/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91d11ebf98971cc35c8b9f70c8f4f48a1b2c177f16a54c6811298e4318962764 +size 36466 diff --git a/BZOJ/3928/data/2.out b/BZOJ/3928/data/2.out new file mode 100644 index 00000000..ca028462 --- /dev/null +++ b/BZOJ/3928/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:118f63f855280b2919b7f3ce4d0a1f4f02a321d36d3e73a75a8447b839a542f1 +size 50