A backpack on a tree
Topic Portal
First of all, is there any dalao who would like to tell me why synthetic premium equipment does not require additional gold coins,
Well, it doesn't matter.
It is clear that the equipment synthesis route can be represented by a tree. One? Silly before the next time only DP a tree, no accident WA,, in a few times, well, seems to be a forest ah (tears)
The easiest to think of Dp[x][i][j] is the X-piece bought I, spent the highest strength of J Yuan. However, this seems to be not to do the problem (Welcome to the road Dalao face, anyway not I said [manual funny] (secretly throw out Fyj gun)), then another way of thinking, or dp[x][i][j], but said is the X-piece equipment, with I-piece synthesis superior equipment (that is, at least bought i), Spend the power of J-Yuan. If I is the basic equipment, the transfer equation comes straight out: d[x][i][j*cost[x]]=power[x]* (j-i).
What if it's an advanced outfit?
Then enumerate how many pieces it buys, and how many pieces of its sub-equipment to buy, direct violence transfer, n^2*times^2. Look at the time limit, 3s, completely non-square
In the next code is ugly, beg you don't mind
#include <bits/stdc++.h>#include<cstdio>#include<cmath>#include<cstring>#include<cstdlib>#include<algorithm>#include<queue>#include<deque>#include<list>#include<Set>#include<vector>#include<iostream>#definell int#defineRe Register#defineINF 0x3f3f3f3f#defineINL Inline#defineSQR (x) (x*x)//#define EPS 1e-8#defineDebug printf ("debug\n");//#pragma COMMENT (linker, "/stack:1024000000,1024000000")//#pragma GCC optimize (2)//#pragma g++ optimize (2)using namespacestd;//const ll MoD;Constll maxn=3e5+Ten; inl ll read () {RE ll x=0; Reintf =1; CharCH =GetChar (); while(ch<'0'|| Ch>'9') {if(ch=='-') F =-1; CH =GetChar ();} while(ch>='0'&&ch<='9') {x= (x<<1) + (x<<3) + (ch^ -); ch=GetChar ();} returnX *F;} INLCharREADC () {CharCh=GetChar (); while(('Z'<ch| | ch<'a') && ('Z'<ch| | ch<'A')) ch=GetChar (); returnch;} INLvoidWrite (re ll x) {if(x>=Ten) Write (x/Ten); Putchar (x%Ten+'0');} INLvoidWriteln (re ll x) {if(x<0) {X=-x;putchar ('-');} Write (x); Puts ("");} INL ll GCD (re ll x,re ll y) { while(y^=x^=y^=x%=y);returnx;} INLvoidFR () {freopen (". in","R", stdin); Freopen (". out","W", stdout);} INLvoidFC () {fclose (stdin); Fclose (stdout);}structNode {ll u,v,w,nxt;} e[20005<<1];ll cnt,head[ -],ssw[ -],g[20005],cost[ -],times[ -];BOOLfl[ -],inch[ -],vis[ -];ll ans[20005];inlvoidAdde (ll u,ll v,ll W) {e[++cnt].u=u;e[cnt].v=v;e[cnt].w=W; E[CNT].NXT=head[u];head[u]=CNT;} ll d[ -][ the][2005],n,m;voidDP (ll x) {if(Vis[x])return; vis[x]=1; if(!fl[x]) {//Basic EquipmentTimes[x]=min (times[x],m/cost[x]); for(Re ll i=times[x];~i;i--) { for(Re ll j=i;j<=times[x];j++) {d[x][i][j*cost[x]]=ssw[x]* (J-i); } } return ; } for(Re ll h=head[x];h;h=e[h].nxt) {DP (E[H].V); Cost[x]+=e[h].w*COST[E[H].V]; TIMES[X]=min (times[x],times[e[h].v]/E[H].W); } Times[x]=min (times[x],m/cost[x]); for(Re ll i=times[x];~i;i--) { for(Re ll j=1; j<=m;j++) g[j]=-inf;g[0]=0; for(Re ll h=head[x];h;h=e[h].nxt) { for(Re ll k=m;~k;k--) {RE ll SST=-inf; for(Re ll l=0; l<=k;l++) {Sst=max (sst,g[k-l]+d[e[h].v][i*E[H].W] [l]);} G[K]=SST;//the highest power the flower K can reach } } for(Re ll j=0; j<=i;j++) { for(Re ll l=0; l<=m;l++) {D[x][j][l]=max (d[x][j][l],g[l]+ssw[x]* (i-j)); } } }}intMain () {//FR ();N=read (), m=read (); memset (Times,inf,sizeof(times)); memset (d,-inf,sizeof(d)); for(Re ll i=1; i<=n;i++) {Ssw[i]=read (); Charsj[3];SCANF ("%s", SJ); if(sj[0]=='A') {Fl[i]=1; Re ll c=read (); for(Re ll j=1; j<=c;j++) {RE ll sx=read (), xs=read (); if(!inch[SX])inch[sx]=1; Adde (I,SX,XS); } } Else if(sj[0]=='B') {Fl[i]=0; cost[i]=read (); Times[i]=read (); } ElsePuts"RE"); } for(Re ll i=1; i<=n;i++) { if(!inch[i]) {//been in the pit countless timesDP (i); for(Re ll j=m;~j;j--) { for(Re ll k=0; k<=j;k++) {Ans[j]=max (ans[j],ans[j-k]+d[i][0][k]); }}}} writeln (Ans[m]);//FC (); return 0;}
[JSOI2008] Warcraft Map