hdu6026
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; const int maxn = 60; const int INF = 0x3f3f3f3f; const int MOD = 1e9 +7; int d[maxn]; char s[maxn][maxn]; int dis[maxn][maxn]; int n; void Dijkstra() { fill(d, d + n, INF); d[0] = 0; for(int i = 0; i < n; i++) { int minn = INF, u = -1; for(int j = 0; j < n; j++) { if(d[j] < minn) { minn = d[j]; u = j; } } if(u == -1) break; for(int j = 0; j < n; j++) { if(d[u] + dis[u][j] < d[j]) d[j] = d[u] + dis[u][j]; } } } int main() { while(cin >> n) { for(int i = 0; i < n; i++) { scanf("%s", s[i]); for(int j = 0; j < n; j++) dis[i][j] = s[i][j] - '0'; } Dijkstra(); ll ans = 1; ll cnt; for(int i = 1; i < n; i++) { cnt = 0; for(int j = 0; j < n; j++) { if(dis[j][i] && d[j] + dis[j][i] == d[i]) cnt++; } ans = ans * cnt % MOD; } cout << ans << endl; } return 0; }
posted on 2019-05-30 09:18 stagelovepig 阅读(126) 评论(0) 编辑 收藏 举报