mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 13:56:26 +00:00
parent
9d82ef9fb8
commit
288c72adb0
51
LibreOJ/10154/10154.cpp
Normal file
51
LibreOJ/10154/10154.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 105;
|
||||
|
||||
int m, n, w[N], f[N][N];
|
||||
std::vector<int> 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;
|
||||
}
|
BIN
LibreOJ/10154/data/choose.bat
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose.bat
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose0.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose0.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose0.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose0.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose1.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose2.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose3.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose4.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/10154/data/choose5.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/10154/data/choose5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user