int n,m; int dp[mxlen][mxlen]; bool vis[mxlen]; int bugs[mxlen],brains[mxlen]; voidprepare(){ l = 0; memset(pre,0,sizeof(pre)); memset(last,0,sizeof(last)); memset(other,0,sizeof(other)); memset(dp,0,sizeof(dp)); memset(vis,false,sizeof(vis)); }
voiddfs(int x){ vis[x] = true; // 向上取整 int needed = (bugs[x]+19)/20; for(int i=needed;i<=m;i++){ dp[x][i] = brains[x]; } for(int p=last[x];p;p=pre[p]){ int y = other[p]; if(vis[y]) continue; dfs(y); for(int i = m;i>=needed;i--){ for(int j=1;j<=i-needed;j++){ //第x节点消耗i个士兵能获得的最大价值 dp[x][i] = max(dp[x][i],dp[x][i-j]+dp[y][j]); } } } }