解题思路:
注意事项:
参考代码:
#include<bits/stdc++.h> using namespace std; struct node { int to; int w; int next; }mp[100005]; int head[100005]; int cnt=0; void add(int a,int b) { mp[++cnt].to=b; mp[cnt].next=head[a]; head[a]=cnt; } int a[100005]; int dp[305][305]; int n,m; void dfs(int u) { for(int i=head[u];i;i=mp[i].next) { int v; v=mp[i].to; dfs(v); for(int j=m+1;j>0;j--) { for(int k=0;k<j;k++) { dp[u][j]=max(dp[u][j],dp[u][j-k]+dp[v][k]); } } } } int main() { cin>>n>>m; for(int i=1;i<=n;i++) { int b; cin>>b>>dp[i][1]; add(b,i); } dfs(0); cout<<dp[0][m+1]; return 0; }
0.0分
0 人评分
分糖果 (C++代码)浏览:1447 |
C语言训练-阶乘和数* (C语言代码)-------- 呆板写法浏览:1362 |
求组合数 (C语言代码)浏览:1159 |
C语言训练-数字母 (C语言代码)浏览:608 |
字符逆序 (C语言代码)浏览:617 |
蚂蚁感冒 (C语言代码)浏览:775 |
数组输出 (C语言代码)浏览:703 |
陶陶摘苹果2 (C语言代码)浏览:601 |
简单的a+b (C语言代码)浏览:830 |
母牛的故事 (C语言代码)浏览:570 |