BZOJ1017: [JSOI2008] Warcraft Map DOTR

Source: Internet
Author: User

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 -in the traditional way ... Set F[i][j][k] represents a subtree with I as the root, to advance the synthesis of J props I provided to the above node, the cost is k when the maximum number of points can be increased strength value. So when we move the enumeration we have to synthesize a few props I. And then make a backpack, probably the first I node cost K can increase the maximum number of points of strength value. and then because the wrong one of the letter was adjusted 2h can not endure.
#include <cstdio>#include<cctype>#include<queue>#include<cmath>#include<cstring>#include<algorithm>#defineRep (i,s,t) for (int i=s;i<=t;i++)#defineDwn (i,s,t) for (int i=s;i>=t;i--)#defineren for (int i=first[x];i;i=next[i])using namespaceStd;inlineintRead () {intx=0, f=1;CharC=GetChar ();  for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1;  for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;}Const intmaxn= -;Const intmaxm=2005;Const intmaxp= the;Const intinf=1e9;Charch[ A];intn,m,first[maxn],next[maxm*Ten],to[maxm*Ten],dis[maxm*Ten],inch[Maxn],e;voidAddedge (intUintVintW) {dis[++e]=w;to[e]=v;next[e]=first[u];first[u]=e;inch[v]++;}intF[MAXN][MAXP][MAXM],G[MAXN][MAXM],P[MAXN],C[MAXN],S[MAXN];voiddpintx) {if(!First[x]) {S[x]=min (S[x],m/c[x]);//Qaq, hit m/p[x] 2333Rep (I,0, S[x]) rep (J,i,s[x]) f[x][i][j*c[x]]= (j-i) *P[x]; return; } S[x]=inf;  for(intI=first[x];i;i=Next[i])        {DP (to[i]); S[X]=min (s[x],s[to[i]]/Dis[i]); C[X]+=c[to[i]]*Dis[i]; } S[x]=min (s[x],m/c[x]); Memset (g,-0x3f3f3f3f,sizeof(g)); g[0][0]=0; Dwn (Y,s[x],0) {        intCnt=0;  for(intI=first[x];i;i=Next[i]) {CNT++; Dwn (J,m,0) Rep (k,0, j) G[cnt][j]=max (g[cnt][j],g[cnt-1][j-k]+f[to[i]][y*Dis[i]]        [K]); } Rep (J,0, y) Rep (k,0, m) F[x][j][k]=max (f[x][j][k],g[cnt][k]+p[x]* (yj)); }}intMain () {memset (F,-0x3f3f3f3f,sizeof(f)); N=read (); m=read (); Rep (I,1, N) {P[i]=read (); scanf ("%s", CH); if(ch[0]=='A') {            intk=read (), v,w;  while(k--) V=read (), w=read (), Addedge (I,V,W); }        ElseC[i]=read (), s[i]=read (); }    intans=0; Rep (I,1, N)if(!inch[i]) {DP (i); Rep (J,0, m) Ans=max (ans,f[i][0][j]); } printf ("%d\n", ans); return 0;}
View Code

BZOJ1017: [JSOI2008] Warcraft Map DOTR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.