Bzoj 1017 Warcraft Map Dotr (tree dp)

Source: Internet
Author: User

Test instructions: There are two types of equipment, advanced equipment A and basic equipment B. Now there's M's money. Each b has a unit price and a maximum quantity that can be purchased. Each AI can be synthesized by other objects of CI, giving the number of other items required for CI species. Each outfit has a contribution value. The maximum contribution value. The synthetic route of known items is a strict tree model. There is one item that does not synthesize any other item, and the rest will only be used to synthesize another item.

Idea: F[i][j][k], representing the I-item, spent J, which offered K I goods.

1#include <algorithm>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <iostream>6 intf[ -][2005][ the];7 intnum[20005],a[20005],b[20005],c[ the][ the],d[ the][ the];8 intn,m,vis[200005],dp[ -][2005],w[20005],pd[20005];9 voidDfsintx) {Ten     if(!Num[x]) { OneB[x]=std::min (b[x],m/a[x]); A          for(intI=0; i<=b[x];i++) -           for(intj=0; j<=i;j++) -f[x][i*a[x]][j]=w[x]* (I-j); the         return;  -     } -b[x]=0x7fffffff; -      for(intI=1; i<=num[x];i++){ +         intPur=C[x][i]; - dfs (PUR); +B[x]=std::min (b[x],b[pur]/d[x][i]); Aa[x]+=d[x][i]*A[pur]; at     } -B[x]=std::min (b[x],m/a[x]); -      for(intt=0; t<=b[x];t++){ -memset (dp,-0x3f3f3f3f,sizeofDP); -dp[0][0]=0;  -          for(intI=1; i<=num[x];i++) in           for(intj=0; j<=m;j++) -            for(intk=0; k<=j;k++) toDp[i][j]=std::max (dp[i][j],dp[i-1][j-k]+f[c[x][i]][k][t*D[x][i]]); +          for(intj=0; j<=m;j++) -           for(intk=0; k<=t;k++) theF[x][j][k]=std::max (f[x][j][k],dp[num[x]][j]+ (t-k) *w[x]); *     } $ }Panax Notoginseng intMain () { -     Chars[ -]; thescanf"%d%d",&n,&m); +      for(intI=1; i<=n;i++){ Ascanf"%d",&w[i]); thescanf"%s", s+1); +         if(s[1]=='A') pd[i]=1;Elsepd[i]=0; -num[i]=0; $         if(pd[i]==0) { $scanf"%d%d",&a[i],&b[i]); -num[i]=0; -           Continue; the         } -scanf"%d",&num[i]);Wuyi          for(intj=1; j<=num[i];j++){ thescanf"%d%d",&c[i][j],&d[i][j]); -vis[c[i][j]]=1;  Wu         } -     } About     inti; $      for(i=1; i<=n;i++)if(!vis[i]) Break; -     introot=i; -memset (f,-0x3f3f3f3f,sizeoff); - Dfs (root); A     intans=0; +      for(intI=0; i<=m;i++) the       for(intj=0; j<=b[root];j++) -ans=Std::max (Ans,f[root][i][j]); $printf"%d\n", ans);  the}

Bzoj 1017 Warcraft Map Dotr (tree dp)

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.