Why the complexity of DP has also become metaphysical in these days >_<
At first I thought it would be tle. Finally unable to run to the membrane Huang long http://hzwer.com/5198.html
F[I][J][K] denotes a subtree with I as the root, with J-pieces equipped I for his father's synthesis, a total cost of K-yuan Maximum strength value ...
Specific practices See the >_< ...
YY a few small pruning (though not very soon). One is to find out the maximum amount of money that may be spent in the current subtree, so that you do not have to enumerate = = at a time from M, and the other is that the number of devices used to synthesize the father is obviously unnecessary more than the number required for the father's equipment.
Measured, handwritten max,min function after the speed is the original more than once .... No change in speed after removing all inline and register = =
The total time complexity is probably O (100*n*m*m)? About more than 20 billion ... There's no real sense in it anyway >_<
Cherish constant away from STL.
1#include <cstdio>2#include <iostream>3#include <cstring>4 using namespacestd;5 Const intinf=1002333333;6 structzs{7 intToo,pre,num;8}e[23333];intlast[ -],tot;9 intf[ -][101][2023],mxnum[ -],v[ -],cost[ -],fa[ -],dl[ -],mxneed[ -],mxcost[ -];Ten intg[2023]; One intI,j,k,n,m,a,b,ans; A - intRaCharRx; -InlineintRead () { theRx=getchar (), ra=0; - while(rx<'0'|| Rx>'9') rx=GetChar (); - while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnRA; - } +InlinevoidInsertintAintBintnum) { -e[++tot].too=b,e[tot].num=num,e[tot].pre=last[a],last[a]=tot; + } AInlineintMinintAintb) {returnA<b?a:b;} atInlineintMaxintAintb) {returnA<b?b:a;} -InlinevoidPrerun () { -RegisterintI,l,r,now; - for(l=r=0, i=1; i<=n;i++)if(!fa[i]) dl[++r]=i; - while(l<R) - for(i=last[now=dl[++l]];i;i=e[i].pre) indl[++r]=E[i].too; - for(i=r;i;i--)if(!Cost[dl[i]]) { tomxnum[dl[i]]=inf; + for(j=last[dl[i]];j;j=e[j].pre) -cost[dl[i]]+=cost[e[j].too]*E[j].num, theMxnum[dl[i]]=min (mxnum[dl[i]],mxnum[e[j].too]/e[j].num); *Mxnum[dl[i]]=min (mxnum[dl[i]],m/Cost[dl[i]]); $ }Panax Notoginseng for(i=1; i<=r;i++) - for(j=last[dl[i]];j;j=e[j].pre) themxneed[e[j].too]=mxnum[dl[i]]*E[j].num; + //Equip x may have up to mxneed[x] a synth for his father. A } the voidDfsintXintFA) { +RegisterintI,j,j1,k,to,vx,costx,numto,costto; - if(!Last[x]) { $ for(i=0; i<=mxnum[x];i++) $ for(J=max (0, I-mxneed[x]); j<=i;j++) f[x][i-j][i*cost[x]]=j*V[x]; -mxcost[x]=mxnum[x]*Cost[x]; - return; the } - Wuyi for(i=last[x];i;i=e[i].pre) theDFS (E[I].TOO,X), Mxcost[x]+=mxcost[e[i].too];//mxcost: How much can it cost? - if(mxcost[x]>m) mxcost[x]=m; Wu for(i=costx=0; i<=mxnum[x];i++,costx+=Cost[x]) { -Memset (G, $, (mxcost[x]+1) <<2), g[0]=0; About for(to=e[j1=last[x]].too;j1;to=e[j1=E[j1].pre].too) $ for(numto=i*e[j1].num,costto=cost[to]*numto,j=mxcost[x]-costx;j;j--) - for(k=j;k;k--) G[j]=max (g[j],g[j-k]+f[to][numto][k+Costto]); - - for(J=min (I,mxneed[x]), vx= (i-j) *v[x];j>=0; J--, Vx+=v[x])//with a J-Kit x synth A for(k=costx,j1=0; k<=mxcost[x];k++,j1++) + if(G[j1]+vx>f[x][j][k]) f[x][j][k]=g[j1]+VX; the } - } $ the intMain () { theN=read (), M=read ();CharID; the for(i=1; i<=n;i++){ thev[i]=read (); - for(Id=getchar ();id<'A'|| Id>'B'; id=GetChar ()); in if(id=='B') Cost[i]=read (), Mxnum[i]=min (read (), m/cost[i]); the Else for(K=read (), j=1; j<=k;j++) A=read (), insert (I,a,read ()), fa[a]=i; the } About Prerun (); the for(i=1; i<=n;i++) for(j=0; j<=mxneed[i];j++) memset (F[i][j], $, (m+1) <<2); the for(i=1; i<=n;i++)if(!fa[i]) {//There is only one tree = = theDFS (I,0); + for(j=0; j<=m;j++)if(f[i][0][j]>ans) ans=f[i][0][j]; - } theprintf"%d\n", ans);Bayi return 0; the}
View Code
[bzoj1017]: [JSOI2008] Warcraft Map DOTR