Title: https://www.lydsy.com/JudgeOnline/problem.php?id=1017
What a very difficult state to think! F[I][J][K] Indicates that item I has a J-upward contribution, altogether spent the maximum power of k money;
G[I][J] used in a subtree, representing the maximum value of J money for the former I subtree;
Half the morning, finally found that the original is less to see a range, f the second dimension of the range is not 51 but 100 ah ah ah ah ah!
In addition to this question there are a lot of things to note, written in the comments.
The code is as follows:
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;int Constmaxn= -, maxm=2005, inf=1000000000;intn,m,l[maxn],m[maxn],p[maxn],head[maxn],ct;intf[maxn][maxn<<1][MAXM],G[MAXN][MAXM],RD[MAXN],H[MAXN][MAXM];structn{intto,next,w; N (intt=0,intn=0,intw=0): to (T), Next (N), W (w) {}}edge[20005];voiddpintx) { if(!head[x])//leaves{l[x]=min (L[x],m/m[x]);//! for(intI=0; i<=l[x];i++)//Have I a for(intj=0; j<=i;j++)//Contribution Jf[x][j][m[x]*i]=p[x]* (I-j); return;//!!!!!!!!!!} L[x]=inf;//there's no limit to advanced equipment. for(intI=head[x],u;i;i=Edge[i].next) {u=edge[i].to; DP (U); L[X]=min (l[x],l[u]/EDGE[I].W); M[X]+=M[U]*EDGE[I].W;//} L[x]=min (l[x],m/m[x]); Memset (g,-0x3f,sizeofg);//!!g[0][0]=0;//!! for(intl=l[x];l>=0; l--)//x items have a l//Reverse! //L can have 0!!!!!!!!!!! { inttot=0;//memset (g,0,sizeof g);//put it on the outside! for(intI=head[x],v;i;i=Edge[i].next) {v=edge[i].to; Tot++; for(intj=0; j<=m;j++)//There's J money altogether . for(intk=0; k<=j;k++)//give V K moneyG[tot][j]=max (g[tot][j],g[tot-1][j-k]+f[v][l*EDGE[I].W] [K]); //G will not re-assign the initial value, so I need to reverse the order to ensure that this time must be synthetic L x items } for(intj=0; j<=l;j++) for(intk=0; k<=m;k++) F[x][j][k]=max (f[x][j][k],g[tot][k]+p[x]* (lj)); } }intMain () {scanf ("%d%d",&n,&m); CharDC;//memset (l,0x3f,sizeof L);memset (f,-0x3f3f3f3f,sizeoff); for(intI=1, x,a,b;i<=n;i++) {scanf ("%d",&P[i]); CIN>>DC; if(dc=='A') {scanf ("%d",&x); while(x--) {scanf ("%d%d",&a,&b); edge[++ct]=n (a,head[i],b); head[i]=CT; Rd[a]++; } } Elsescanf"%d%d",&m[i],&L[i]); } inttot=0; for(intI=1; i<=n;i++) if(!Rd[i]) {Tot++; DP (i); for(intj=0; j<=m;j++) for(intk=0; k<=j;k++) for(intL=0; l<=l[i];l++) H[tot][j]=max (h[tot][j],h[tot-1][k]+f[i][l][j-K]); } intans=0; for(intj=0; j<=m;j++) ans=Max (ans,h[tot][j]); printf ("%d\n", ans); return 0;}
bzoj1017 [JSOI2008] Warcraft Map DOTR--DP