Bzoj 2165 Building Multiplier Floyd

Source: Internet
Author: User

Topic: Given a picture, the weight from 1 to reach m must at least traverse how many edges

n<=100, decisive multiplication Floyd

F[TEMP][I][J] Indicates the maximum weight from I to J through the 2^temp Edge.

Update F[temp[i][j]=max{f[temp-1][i][k]+f[temp-1][k][j]}

Then use matrix G[i][j] to record the current weight of the walk, the initial main diagonal is 0, the rest is-∞

From large to small enumeration temp, using f[temp] and g to get matrix H

If the weight in H 1 to a point exceeds m, the current temp is counted in ans and the G array is updated to H

The final output ans+1 is the answer to a slightly

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;int N;long Long f[70][110][110],g[110][110],h[110][110],m,ans;void Initialize () {Ans=0;memset (f,0xef,sizeof f); memset (g,0xef,sizeof g);} int main () {int t,i,j,k,temp;for (cin>>t; T t--) {Initialize (); Cin>>n>>m;for (i=1;i<=n;i++) for (j=1;j<=n;j++) {#ifndef online_judgescanf ("%I 64d ", &f[0][i][j]); #elsescanf ("%lld ", &f[0][i][j]); #endifif (!f[0][i][j]) f[0][i][j]=0xefefefefefefefefll;} Try{for (temp=1;1ll<<temp<=m;temp++) for (k=1;k<=n;k++) for (i=1;i<=n;i++) for (j=1;j<=n;j++) {f[ Temp][i][j]=max (F[temp][i][j],f[temp-1][i][k]+f[temp-1][k][j]); if (i==1&&f[temp][i][j]>=m) throw (true );}} catch (bool) {}for (i=1;i<=n;i++) g[i][i]=0;while (temp--) {memset (h,0xef,sizeof h); Try{for (k=1;k<=n;k++) for (i= 1;i<=n;i++) for (j=1;j<=n;j++) {H[i][j]=max (h[i][j],f[temp][i][k]+g[k][j]); if (i==1&&h[i][j]>=m) throw (true);} memcpy (g,h,sizeof g); anS+=1ll<<temp;} catch (bool) {}}cout<<ans+1<<endl;} return 0;} LLD!!!!


Bzoj 2165 Building Multiplier 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.