Topic: Given a map, each point has the right value, the ant from a node, the initial physical strength of 1, each walk a side of the physical value of *=p, each pass a point will get happiness value for the point of the weight * physical value, to find the maximum happiness value
Make f[i][j][t] The maximum happiness value of J Flower 2^t step to go from point I to
Then there is f[i][j][t]=max{f[i][k][t-1]+f[k][j][t-1]*p^ (2^t)}
The approximate value of an answer can be obtained by iterating multiple times
Note that the ant may be stuck at some point, so the initial adjacency matrix is cleared to-inf, and then each point is connected to a self-loop with a 0 edge
Also note that the weight of the last point passed at the end of the card will not be counted here may hang
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < Algorithm> #define M 110using namespace Std;int n,m,st;double p,ans,a[m],f[m][m],g[m][m];int main () {int i,j,k,t,x,y; Cin>>n>>m;for (i=1;i<=n;i++) scanf ("%lf", &a[i]); Cin>>st>>p;memset (f,0xc2,sizeof f) ; for (i=1;i<=n;i++) f[i][i]=0;for (i=1;i<=m;i++) {scanf ("%d%d", &x,&y); f[x][y]=a[y];} Double Temp=p;for (t=0; t<=70; T++,temp*=temp) {memset (g,0xc2,sizeof g); for (k=1;k<=n;k++) for (i=1;i<=n;i++) for (j=1;j<=n;j++) G[i][j]=max (g[i][j],f[i][k]+f[k][j]*temp); memcpy (f,g,sizeof f);} for (i=1;i<=n;i++) Ans=max (Ans,f[st][i]);p rintf ("%.1lf\n", Ans*p+a[st]); return 0;}
Bzoj 2306 Ctsc2011 Happiness path multiplication Floyd