BZOJ1017: [JSOI2008] Warcraft Map Dotr

Source: Internet
Author: User

Portal

The $f[i][j][k]$ indicates that for the $i$ point, contributions to the parent node $j$ the synthesized equipment, cost the $k$, the maximum gain of the power Value.

Simple $f[i][j][k]$ is difficult to transfer, the main reason is unable to maintain the relationship with other Sons. So for each node then a $g[i][j]$ represents the maximum strength value that the former $i$ son of the current point spends for $k$ can Get.

Then be sure to update $g[][]$ and $g[][]$ to update the $f[][][]$.

The state transition equation for $g[i][j]$ is listed As:

$g [cnt][k]=max \{f[son][tol \times edge_v][j] + g[cnt-1][k-j] \}$

Where $tol$ represents the total amount of equipment to be synthesized at the current Point.

Then update the $f[i][j][k]$ according to $g[i][k]$:

$f [i][j][k]= Max \{g[cnt_{max}][k]+ (tol-j) \times power_i \} $

And then you can have a pleasant transfer.

I see other people's code about $tol$ enumeration is decremented thereby reducing unnecessary memset. Not very understanding, hope God Ben Message to tell me qaq, but direct memset will not time Out.

Bzoj 1017//by cydiater//2016.10.26#include <iostream> #include <cstring> #include <string># Include <algorithm> #include <queue> #include <map> #include <ctime> #include <cmath># Include <cstdlib> #include <cstdio> #include <iomanip> #include <bitset>using namespace std;# Define ll long long#define up (i,j,n) for (int. I=j;i<=n;i++) #define down (i,j,n) for (int i=j;i>=n;i--) #define Cmax (a, B) A=max (a, a,) #define Cmin (a, b) a=min (a, b) const int MAXN=1E4+5;CONST int Oo=1000000001;inline int read () {char Ch=getchar ( ); int x=0,f=1;while (ch> ' 9 ' | | ch< ' 0 ') {if (ch== '-') F=-1;ch=getchar ();} While (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} Return x*f;} int N,m,len=0,link[maxn],f[55][105][2005],power[maxn],cost[maxn],lim[maxn],indu[maxn],g[55][maxn],ans=0;bool Tag [maxn];struct Edge{int y,next,v;} E[maxn];namespace solution{inline void Insert (int x,int y,int v) {e[++len].next=link[x]; link[x]=len;e[len].y=y;e[len].v=v;} void Init () {memset (indu,0,sizeof (indu)); N=read (); M=read (); up (i,1,n) lim[i]=oo;up (i,1,n) {power[i]=read (); char ch;scanf ("%c", &ch); tag[i]= (ch== ' A ')? 1:0;if (tag[i ] {int tmp=read (), while (tmp--) {int y=read (), v=read (), Insert (i,y,v); indu[y]++;}} Else{cost[i]=read (); Lim[i]=read ();}}} void TREEDP (int node) {if (!tag[node]) {cmin (lim[node],m/cost[node]); up (i,0,lim[node]) up (j,0,i) f[node][j][i*cost[ node]]=power[node]* (i-j);} Else{lim[node]=oo;for (int I=link[node];i;i=e[i].next) {TREEDP (e[i].y); cmin (lim[node],lim[e[i].y]/e[i].v); cost[node]+=e[i].v*cost[e[i].y];} Cmin (lim[node],m/cost[node]); up (tol,0,lim[node]) {int cnt=0;memset (g,-10,sizeof (g)); g[0][0]=0;for (int I=link[node ];i;i=e[i].next) {cnt++;up (j,0,m) up (k,0,j) Cmax (g[cnt][j],g[cnt-1][j-k]+f[e[i].y][e[i].v*tol][k]);} Up (j,0,tol) up (k,0,m) Cmax (f[node][j][k],g[cnt][k]+ (tol-j) *power[node]);}}} void output (int Node) {up (j,0,lim[node]) up (k,0,m) Cmax (ans,f[node][j][k]);}} int main () {freopen ("input.in", "r", stdin), using namespace solution;init (); memset (f,-10,sizeof (f)); up (i,1,nIf (indu[i]==0) {treedp (i); output (i);} Cout<<ans<<endl;return 0;}

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.