Meaning of the questions: A small company requires each morning arrive before 6:00, otherwise cleared salary this month. A small but happens to have a bad habit of stay in bed. So in order to keep his salary, he bought a small A foot space is a very cow B, every second can run 2 ^ k kilometers. Of course, this machine longint is stored, so the total foot length can not exceed maxlongint km. A small home to the company can be viewed as a way to view a small point A home, a company point n, the length of each edge are one thousand meters. A small day want to be able to wake up as late as possible, so let him help you calculate, he needs at least a few seconds to get to the company. A data path to ensure that at least 1 to n.
Solution: multiplying + Floyd;
1. multiplier; topic that may run on foot 2 ^ k kilometers per second, it may occur naturally multiplier; set f [i] [j] [k] represents the point i to point j whether through 2 ^ k to go away, and if so, will be f [i] [j] [k] value of 1;
2.Floyd; see n subject to the so small, good writing ...... Floyd; Floyd used to initialize the first f [i] [j] [k], dp request for a second minimum number of Floyd;
Attach Code:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N = 86; const int inf = 0x3f3f3f3f; int n,m; int a[N][N][N]; int f[N][N]; int main() { scanf("%d%d",&n,&m); memset(f,inf,sizeof(f)); for(int i=1;i<=m;++i){ int x,y; scanf("%d%d",&x,&y); a[x][y][0]=f[x][y]=1; } for(int cnt=1;cnt<=64;++cnt) for(int k=1;k<=n;++k) for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(a[i][k][cnt-1]&&a[k][j][cnt-1]) a[i][j][cnt]=f[i][j]=1; for(int k=1;k<=n;++k) for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) f[i][j]=min(f[i][j],f[i][k]+f[k][j]); printf("%d",f[1][n]); return 0; }