标签:highlight amp anti 而不是 target void auto c++ tar
题目链接 课程学分总数
很基础的树型DP。注意输入数据可能是森林而不是完整的一棵树。#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define dec(i, a, b) for (int i(a); i >= (b); --i) typedef long long LL; const int N = 305; int f[N][N], sz[N], c[N]; vector <int> v[N]; int n, m; void dfs(int x){ sz[x] = 1; f[x][1] = c[x]; for (auto u : v[x]){ dfs(u); dec(i, sz[x], 1) rep(j, 1, sz[u]) f[x][i + j] = max(f[x][i + j], f[x][i] + f[u][j]); sz[x] += sz[u]; } } int main(){ scanf("%d%d", &n, &m); ++n, ++m; rep(i, 2, n){ int x, y; scanf("%d%d", &x, c + i); ++x; v[x].push_back(i); } dfs(1); printf("%d\n", f[1][m]); return 0; }
标签:highlight amp anti 而不是 target void auto c++ tar
原文地址:http://www.cnblogs.com/cxhscst2/p/7214342.html