Occupy a pit first.
The puzzle is written, the code does not want to write.
Bzoj 1017 DP Derivation, no code. (I'm not going to tell you it's my code won't write it) first we can see that this is a tree DP but different from the usual tree DP which is merged by the son node to the parent node. Set F[i][j][k] Represents a subtree with I as the Root contributing J to his father node, the largest power we can get from K is divided into two states. I is the leaf node: f[i][j][k*cost[i]]= (K-J) *power ([i]); K*cost[i] means that at this point, the power of the point is not included in the second half of what is given to his father. I am not a leaf node: This transfer is quite strange. We need to set an intermediate array g[i][j] to indicate that the first I node in the subtree with the root of X takes the maximum power that J can get G[cnt][j]=max{g[cnt-1][k]+f[x ' son][l*res][j-k]}; This place is very difficult to understand. Split Line (explanation) CNT is the variable of the enumeration, which means that we have enumerated to the first point. First we from the large to the small enumeration L, the X this point to buy L, G[cnt-1][k] represents the previous state f[x ' son][l*res][j-k] in the res represents the point of the remaining quantity can be purchased, [J-k] is two differential value End We can further deduce ff[x][j][k]=max{g[size[x]][k]+ (L-J) *power[x] According to this G; Note: The cost of the price is the same, the composition does not need to be spent. So at the end of each root node running on one side ans array can be, the same method as above. Ans[cnt][j]=max{ans[cnt-1][k]+f[x][tmp (0<=tmp<=limit[x])][j-k]};
BZOJ1017[JSOI2008] Warcraft Map DOTR