modify code

pull/3/head
左程云 5 years ago
parent d86c49c539
commit 0e0eb7fe62

@ -23,14 +23,19 @@ public class Code09_MaxHappy {
return process1(boss, false); return process1(boss, false);
} }
// 当前来到的节点叫cur
// up表示cur的上级是否来
// 该函数含义:
// 如果up为true表示在cur上级已经确定来的情况下cur整棵树能够提供最大的快乐值是多少
// 如果up为false表示在cur上级已经确定不来的情况下cur整棵树能够提供最大的快乐值是多少
public static int process1(Employee cur, boolean up) { public static int process1(Employee cur, boolean up) {
if (up) { if (up) { // 如果cur的上级来的话cur没得选只能不来
int ans = 0; int ans = 0;
for (Employee next : cur.nexts) { for (Employee next : cur.nexts) {
ans += process1(next, false); ans += process1(next, false);
} }
return ans; return ans;
} else { } else { // 如果cur的上级不来的话cur可以选可以来也可以不来
int p1 = cur.happy; int p1 = cur.happy;
int p2 = 0; int p2 = 0;
for (Employee next : cur.nexts) { for (Employee next : cur.nexts) {

Loading…
Cancel
Save