Bzoj 2306 Ctsc2011 Happiness path multiplication Floyd

Source: Internet
Author: User

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

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.