1017: [JSOI2008] Warcraft map dotr time limit:30 Sec Memory limit:162 MB
submit:1243 solved:532
[Submit] [Status] [Discuss] Description
DOTR (Defense of the Robots) Allstars is a popular global Warcraft map, his rules are simple with the same popular map DotA (Defense of the Ancients) Allstars. The hero inside the DOTR has only one attribute--power. They need to buy equipment to boost their strength, and each piece of equipment can raise a fixed number of points for the hero's strength, so the hero's strength is equal to the strength of all the equipment it buys. Equipment is divided into basic equipment and high-level equipment two kinds. Basic equipment can be purchased directly from the store with gold coins, while advanced equipment needs to be crafted with basic equipment or a lower level of advanced equipment that does not require additional gold. The synthetic route of the equipment can be represented by a tree. For example, the synthesis of Sange and Yasha requires Sange, Yasha and Sange and Yasha Recipe scroll three-like items. Among them Sange again with Ogre Axe, Belt of Giant strength and sange Recipe scroll synthesis. There is a limit to the number of basic equipment, which limits your inability to synthesize certain cost-effective equipment without restriction. Now, hero Spectre has m gold coins, he wants to use the money to buy equipment to make his strength value as high as possible. Can you help him? He will teach you magical haunt (ghost possession) in return.
Input
The first line of the input file contains two integers, n (1 <= n <= 51) and M (0 <= m <= 2,000). Indicates the number of types and coins of the equipment, respectively. Equipped with an integer number of 1 to N. The next n lines, in the order of equipment 1 to equipment N, describe a device in each line. The first positive integer of each line represents the strength value of the equipment contribution. The next non-null character indicates whether the equipment is basic or advanced, a for advanced equipment, and b for basic equipment. In the case of basic equipment, the next two positive integers represent the unit price (in gold coins) and the quantity limit (no more than 100). If it is an advanced equipment, followed by a positive integer c, indicating that the advanced equipment requires C low-level equipment. The following 2C number, in turn, describes the type of a low-level equipment and the number of needs.
Output
The first line contains an integer s that represents the maximum number of point strength values that can be lifted.
Sample Input10 59
5 A 3 6 1 9 2 10 1
1 B 5 3
1 B 4 3
1 B 2 3
8 A 3 2 1 3 1 7 1
1 B 5 3
5 B 3 3
3 A 1 1 5 1 4 1
1 B 3 5
1 B 4 3Sample Output -HINT Source
A: ...
The direct move Huang long good ...
Set P[X],L[X],M[X], indicating the energy of item x, purchase cap and price
L[x]=min (L[x],m/m[x])
Advanced equipment, M and L, just a little bit of DP.
Then use F[i][j][k] to express the article I, there are j pieces for the upper layer of synthesis, spend money is K can obtain the greatest strength
For a subtree that is rooted in X, enumerate the compositions of L x items, and then buy some of the x subtrees with the rest of the money. Not for crafting
Enumerate the number of synthetic items L, using g[i][j] to represent the child of the first I son of X, spend J's money, the maximum power that can be obtained
G[TOT][J]=MAX{G[TOT-1][J-K]+F[E[I].TO][L*E[I].V][K]}
E[i].to is the son node, E[I].V is the required quantity, is to take out K from J money in the e[i].to of the sub-tree purchase
The last enumeration of the synthesized L x items has J is directly used to increase the strength, the remainder is used to synthesize the
f[x][j][k]=max{g[tot][k]+p[x]* (L-J)}
The code is almost according to Huang long copy of the ... No way to be too weak ...
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn= -+Ten, maxm= -+Ten, maxt= -+Ten, maxe=200000+Ten, inf=1e8; One structted{intX,Y,W;TED*NXT;} adj[maxe],*fch[maxn],*ms=adj; A intN,m,cnt,ans; - intP[MAXN],L[MAXN],M[MAXN],F[MAXN][MAXT][MAXM],G[MAXN][MAXM],DEG[MAXN]; - voidAddintXintYintW) {*ms= (Ted) {x,y,w,fch[x]};fch[x]=ms++;d eg[y]++;return;} the voiddpintx) { - if(!Fch[x]) { -L[x]=min (l[x],m/m[x]); - for(intI=0; i<=l[x];i++) + for(intj=i;j<=l[x];j++) -f[x][i][j*m[x]]= (j-i) *P[x]; + return; A}l[x]=inf; at for(ted*e=fch[x];e;e=e->NXT) { - intV=e->Y;DP (v); -L[x]=min (l[x],l[v]/e->W); -m[x]+=e->w*M[v]; -}l[x]=min (l[x],m/m[x]); -memset (g,-0x3f3f3f3f,sizeof(g)); ing[0][0]=0; - for(intl=l[x];l>=0; l--){ to inttot=0; + for(ted*e=fch[x];e;e=e->NXT) { -tot++; the for(intj=0; j<=m;j++) * for(intk=0; k<=j;k++) $G[tot][j]=max (g[tot][j],g[tot-1][j-k]+f[e->y][l*e->W] [K]);Panax Notoginseng } - for(intj=0; j<=l;j++) the for(intk=0; k<=m;k++) +F[x][j][k]=max (f[x][j][k],g[tot][k]+p[x]* (lj)); A}return; the } +InlineintRead () { - intx=0, sig=1;CharCh=GetChar (); $ while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} $ while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); - returnx*=Sig; - } theInlinevoidWriteintx) { - if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x;Wuyi intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; the for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } WuInlineCharREADC () { - CharCh=getchar (); while(!isalpha (CH)) Ch=getchar ();returnch; About } $ voidinit () { -memset (f,-0x3f3f3f3f,sizeof(f)); -N=read (); m=read (); - for(intI=1; i<=n;i++){ Ap[i]=read (); + if(READC () = ='A'){ the intx=read (); - while(x--){ $ intV=read (), num=read (); the Add (i,v,num); the } the } the ElseM[i]=read (), l[i]=read (); - } in return; the } the voidWork () { About for(intx=1; x<=n;x++)if(!Deg[x]) { the DP (x); the for(intI=0; i<=m;i++) the for(intj=0; j<=l[x];j++) +ans=Max (ans,f[x][j][i]); - } the return;Bayi } the voidprint () { the write (ans); - return; - } the intMain () {init (); work ();p rint ();return 0;}
VFK seems to have a more curious idea ... but do you think I can read it? = =
Bzoj [JSOI2008] Warcraft Map DOTR