"Bzoj 1017" [JSOI2008] Warcraft Map DOTR

Source: Internet
Author: User

1017: [JSOI2008] Warcraft map DOTR Time limit: $ Sec Memory Limit: 162 MB
Submit: 1069 Solved: 433
[Submit] [Status] 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 -

More troublesome tree-shaped DP.


Attention to the topic said: The process of synthesis must be satisfied with a tree shape!


DP equation:

F[i][j][k] represents the first I equipment spend K money, contribute J to the superior of the maximum strength, g[tot][j] is currently i the first tot son, total cost J money of the most vigorously

Amount


On top of these two equations, we need to nest a layer of loop all to indicate how many of the equipment I have to do.


So let's first ask for the G array (to be able to do all I):

G[tot][j]=max (G[tot-1][j],g[tot-1][j-k]+f[y][all*num[tot]][k])

(k is the amount of money spent doing the current son, Y is the current son's number, Num[tot] means do 1 I with a few tot)


Continue to ask for the F array under current now:

F[i][j][k]=max (f[i][j][k],g[tot][k]+p[i]* (ALL-J))


Attention:

Now to cycle from large to small, to ensure that the G array is monocytogenes, you can avoid emptying the G array every time.


<span style= "FONT-SIZE:18PX;" > #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include < cmath> #include <cstdlib> #define INF 0x3f3f3f3fusing namespace Std;int in[60],h[60],tot=0,n,m,g[60][2005],l[ 60],p[60],c[60],f[60][106][2005];struct edge{int Y,ne,num;} E[200005];void addedge (int x,int y,int v) {tot++;e[tot].y=y;e[tot].ne=h[x];h[x]=tot;e[tot].num=v;in[y]++;} void dp (int x) {if (!h[x]) {l[x]=min (l[x],m/c[x]); for (int. i=0;i<=l[x];i++) for (int j=i;j<=l[x];j++) f[x][i][j*c[x ]]=p[x]* (j-i); return;} l[x]=m;for (int i=h[x];i;i=e[i].ne) {int y=e[i].y;dp (y); L[x]=min (l[x],l[y]/e[i].num); c[x]+=e[i].num*c[y];} L[x]=min (L[x],m/c[x]); for (int. i=1;i<=n;i++) for (int j=0;j<=m;j++) g[i][j]=-inf;g[0][0]=0;for (int all=l[x];all >=0;all--) {int tot=0;for (int i=h[x];i;i=e[i].ne) {tot++;int y=e[i].y;for (int j=0;j<=m;j++) for (int k=0;k<=j; k++) G[tot][j]=max (G[tot][j],g[tot-1][j-k]+f[y][all*e[i].num][k]);} for (int i=0;i<=all;i++) foR (int k=0;k<=m;k++) F[x][i][k]=max (f[x][i][k],g[tot][k]+p[x]* (All-i));}} int main () {scanf ("%d%d", &n,&m), for (Int. i=1;i<=n;i++) for (int. j=0;j<=105;j++) for (int k=0;k<=m;k+ +) f[i][j][k]=-inf;for (int i=1;i<=n;i++) {scanf ("%d", &p[i]), Char s[5];scanf ("%s", s), if (s[0]== ' B ') scanf ("%d% D ", &c[i],&l[i]); Else{int k;scanf ("%d ", &k), while (k--) {int y,v;scanf ("%d%d ", &y,&v); Addedge (I,Y,V);}}} int ans=0;for (int i=1;i<=n;i++) if (!in[i]) {DP (i); for (int. j=0;j<=m;j++) for (int k=0;k<=l[i];k++) Ans=max (ans, F[I][K][J]); break;} Cout<<ans<<endl;return 0;} </span>




Sentiment:

1. This problem f[i][j][k] This transfer mode of J to the superior several, this transfer mode is the first time to see!


2. This problem VFK has two-dimensional solution, look at

"Bzoj 1017" [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.