From 288c72adb009d9f5d62dedeeec21676b6949d137 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 10 Jun 2022 18:38:45 +0800 Subject: [PATCH] =?UTF-8?q?#10154.=20=E3=80=8C=E4=B8=80=E6=9C=AC=E9=80=9A?= =?UTF-8?q?=205.2=20=E4=BE=8B=202=E3=80=8D=E9=80=89=E8=AF=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1479990 --- LibreOJ/10154/10154.cpp | 51 ++++++++++++++++++++++++++++++++++ LibreOJ/10154/data/choose.bat | 3 ++ LibreOJ/10154/data/choose0.in | 3 ++ LibreOJ/10154/data/choose0.out | 3 ++ LibreOJ/10154/data/choose1.in | 3 ++ LibreOJ/10154/data/choose1.out | 3 ++ LibreOJ/10154/data/choose2.in | 3 ++ LibreOJ/10154/data/choose2.out | 3 ++ LibreOJ/10154/data/choose3.in | 3 ++ LibreOJ/10154/data/choose3.out | 3 ++ LibreOJ/10154/data/choose4.in | 3 ++ LibreOJ/10154/data/choose4.out | 3 ++ LibreOJ/10154/data/choose5.in | 3 ++ LibreOJ/10154/data/choose5.out | 3 ++ 14 files changed, 90 insertions(+) create mode 100644 LibreOJ/10154/10154.cpp create mode 100644 LibreOJ/10154/data/choose.bat create mode 100644 LibreOJ/10154/data/choose0.in create mode 100644 LibreOJ/10154/data/choose0.out create mode 100644 LibreOJ/10154/data/choose1.in create mode 100644 LibreOJ/10154/data/choose1.out create mode 100644 LibreOJ/10154/data/choose2.in create mode 100644 LibreOJ/10154/data/choose2.out create mode 100644 LibreOJ/10154/data/choose3.in create mode 100644 LibreOJ/10154/data/choose3.out create mode 100644 LibreOJ/10154/data/choose4.in create mode 100644 LibreOJ/10154/data/choose4.out create mode 100644 LibreOJ/10154/data/choose5.in create mode 100644 LibreOJ/10154/data/choose5.out diff --git a/LibreOJ/10154/10154.cpp b/LibreOJ/10154/10154.cpp new file mode 100644 index 00000000..5e38c038 --- /dev/null +++ b/LibreOJ/10154/10154.cpp @@ -0,0 +1,51 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 105; + +int m, n, w[N], f[N][N]; +std::vector g[N]; + +void dfs(int u) { + // 一门课也不选学分显然为 0 + f[u][0] = 0; + + for (int v : g[u]) { + dfs(v); + + for (int i = n; ~i; i--) { // 选课总数 + for (int j = i; ~j; j--) { // 子树内选课总数 + f[u][i] = std::max(f[u][i], f[u][i - j] + f[v][j]); + } + } + } + + if (u) { + for (int i = n; i; i--) { + f[u][i] = f[u][i - 1] + w[u]; // 选这门课也应获得相应学分 + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> m >> n; + + for (int i = 1, x; i <= m; i++) { + cin >> x >> w[i]; + + g[x].push_back(i); + } + + dfs(0); + + cout << f[0][n] << endl; + + return 0; +} diff --git a/LibreOJ/10154/data/choose.bat b/LibreOJ/10154/data/choose.bat new file mode 100644 index 00000000..fc9b0e76 --- /dev/null +++ b/LibreOJ/10154/data/choose.bat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b80a79db9b4ce667e306b1e960962da80c4b192842f004d5a6c4ce2799c4ef74 +size 255 diff --git a/LibreOJ/10154/data/choose0.in b/LibreOJ/10154/data/choose0.in new file mode 100644 index 00000000..47fa1ac0 --- /dev/null +++ b/LibreOJ/10154/data/choose0.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dcb9a8b5692bfc2fbf5b5ddb4f5bee8b245dbcf76b8104add66bc3b592a7c1a1 +size 40 diff --git a/LibreOJ/10154/data/choose0.out b/LibreOJ/10154/data/choose0.out new file mode 100644 index 00000000..3e4f7000 --- /dev/null +++ b/LibreOJ/10154/data/choose0.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f7c4f4cc6c99f0e5d21986eaf4e0ee5170b03b05ba444a6b2792a902e38f07b2 +size 4 diff --git a/LibreOJ/10154/data/choose1.in b/LibreOJ/10154/data/choose1.in new file mode 100644 index 00000000..e08b13d8 --- /dev/null +++ b/LibreOJ/10154/data/choose1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c0a4c7653fc4754edf09e282beb8c27df23874df0c304f4e9ec8f40def4e115 +size 25 diff --git a/LibreOJ/10154/data/choose1.out b/LibreOJ/10154/data/choose1.out new file mode 100644 index 00000000..4ba4b0d4 --- /dev/null +++ b/LibreOJ/10154/data/choose1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4593c89b4d60161d78fef3f48312d7833649b876a0c1d762cb5b9d73acaa0a20 +size 4 diff --git a/LibreOJ/10154/data/choose2.in b/LibreOJ/10154/data/choose2.in new file mode 100644 index 00000000..48c14417 --- /dev/null +++ b/LibreOJ/10154/data/choose2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81a6f024722436d11b10d977a512d4fd22d6eefb08899d12f75a12bd3671ef3e +size 15 diff --git a/LibreOJ/10154/data/choose2.out b/LibreOJ/10154/data/choose2.out new file mode 100644 index 00000000..6da6aff2 --- /dev/null +++ b/LibreOJ/10154/data/choose2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df4e26a04a444901b95afef44e4a96cfae34690fff2ad2c66389c70079cdff2b +size 3 diff --git a/LibreOJ/10154/data/choose3.in b/LibreOJ/10154/data/choose3.in new file mode 100644 index 00000000..b743ebc9 --- /dev/null +++ b/LibreOJ/10154/data/choose3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47fe8a4e7bdc1f137b703d48c6db4e9e9b56ff6a45e37e549549b1df48f3e2b0 +size 15 diff --git a/LibreOJ/10154/data/choose3.out b/LibreOJ/10154/data/choose3.out new file mode 100644 index 00000000..6da6aff2 --- /dev/null +++ b/LibreOJ/10154/data/choose3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df4e26a04a444901b95afef44e4a96cfae34690fff2ad2c66389c70079cdff2b +size 3 diff --git a/LibreOJ/10154/data/choose4.in b/LibreOJ/10154/data/choose4.in new file mode 100644 index 00000000..9219da14 --- /dev/null +++ b/LibreOJ/10154/data/choose4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c95ceb30bcd72d64d31a32a72e8fc8535acdc547b853db76aba1314a1bf256a1 +size 30 diff --git a/LibreOJ/10154/data/choose4.out b/LibreOJ/10154/data/choose4.out new file mode 100644 index 00000000..3e4f7000 --- /dev/null +++ b/LibreOJ/10154/data/choose4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f7c4f4cc6c99f0e5d21986eaf4e0ee5170b03b05ba444a6b2792a902e38f07b2 +size 4 diff --git a/LibreOJ/10154/data/choose5.in b/LibreOJ/10154/data/choose5.in new file mode 100644 index 00000000..05475ffb --- /dev/null +++ b/LibreOJ/10154/data/choose5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:75a171465bf8c86bf3f358dae461ec7c0acff9a5935740ce4104a144c4bf8133 +size 603 diff --git a/LibreOJ/10154/data/choose5.out b/LibreOJ/10154/data/choose5.out new file mode 100644 index 00000000..9c3f4fbf --- /dev/null +++ b/LibreOJ/10154/data/choose5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5ad41de2365d9f4464667a73d1c5ae5f6446840d7c3112bb15f229fde9becf5 +size 5