Dynamic planning.
To a fish pond must pass through the former fish pond, and can not be returned after passing. Assuming that the n fish ponds in 1-n are fishing, you can pre-subtract the time required from 1 to n (sooner or later anyway), then ignore the "go-to-go" limit and think that you can switch freely between the fish ponds (because it is equivalent to having enough fish in one pond to catch a predetermined number of times to the next fish pond).
Use the heap to maintain and find the most efficient fish ponds, and go there to fish, then update the heap ... Keep repeating until the time is up.
1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <queue>8 using namespacestd;9 Const intmxn= *;Ten structfh{ One intf,d; A intID; - }A[MXN]; - the BOOL operator< (ConstFH X,ConstFH y) { - if(X.F!=Y.F)returnx.f<y.f; - returnX.id>y.id; - } +priority_queue<fh>q;//default Dagen - intDIS[MXN]; + intANS[MXN],TMP[MXN]; A intN; at voidinit () { -memset (ans,0,sizeofans); -Memset (A,0,sizeofa); -dis[1]=0; - } - intMain () { in while(SCANF ("%d", &n) &&N) { - init (); to intTime ; +scanf"%d",&Time ); -time*= A;//The read-in time is measured in hours, and the actual calculation is 5 minutes as a unit the inti,j; * for(i=1; i<=n;i++) a[i].id=i; $ for(i=1; i<=n;i++) scanf ("%d",&a[i].f);Panax Notoginseng for(i=1; i<=n;i++) scanf ("%d",&a[i].d); - for(i=2; i<=n;i++){ thescanf"%d",&j); +dis[i]=j+dis[i-1]; A } theans[0]=-1; + for(i=1; i<=n;i++){ - intmx=0; $memset (TMP,0,sizeoftmp); $ intBas=time-dis[i];//time available for fishing - while(!q.empty ()) Q.pop (); - for(j=1; j<=i;j++) Q.push (A[j]); the FH x; - while(bas>0){//FishingWuyix=q.top (); the Q.pop (); -bas--; Wumx+=x.f; -tmp[x.id]++; Aboutx.f-=x.d; $ if(x.f<0) x.f=0; - Q.push (x); - } - if(mx>ans[0]){//Update Answer Aans[0]=MX; + for(j=1; j<=i;j++) ans[j]=Tmp[j]; the } - } $ for(i=1; i<n;i++) printf ("%d,", ans[i]*5); theprintf"%d\n", ans[n]*5); theprintf"Number of fish expected:%d\n\n", ans[0]); the } the return 0; -}
POJ1042 Gone Fishing