이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
/*
Let dp[u][d] be the maximum amount of juice that can be collected if the edge (u, p[u]) is cut on day d.
Let dp'[u][d] = max{d1 <= d | dp[u][d]}
dp[u][d] = (d == fruit_day[u]) * fruit_weight[u]
+ sum{v in children[u] | dp'[v][d]}
dp'[u][d] = max(dp'[u][d-1], dp[u][d])
*/
int main()
{
int n, m, k;
cin >> n >> m >> k;
vector<int> children[n+1];
for(int i = 2; i <= n; i++)
{
int p;
cin >> p;
children[p].push_back(i);
}
vector<int> fruit_day(n+1, 1);
vector<long long> fruit_weight(n+1, 0);
for(int f = 1; f <= m; f++)
{
int v, d, w;
cin >> v >> d >> w;
fruit_day[v] = d;
fruit_weight[v] = w;
}
vector< vector<long long> > dp(n+1, vector<long long>(k+1, 0));
vector< vector<long long> > dp1(n+1, vector<long long>(k+1, 0));
for(int u = n; u >= 1; u--)
{
dp[u][0] = 0;
dp1[u][0] = 0;
for(int d = 1; d <= k; d++)
{
dp[u][d] = (d == fruit_day[u]) * fruit_weight[u];
for(int v: children[u])
dp[u][d] += dp1[v][d];
dp1[u][d] = max(dp[u][d], dp1[u][d-1]);
}
}
cout << dp1[1][k] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |