2019-05-13 19:25:59 C++

C++

Copy Copied! Full
#include <bits/stdc++.h> using namespace std; #define INF 1e9+7 int main(void){ int N = 4; vector<vector<int>> d(5,vector<int>(5,INF)); for(int i=1;i<=4;i++)d[i][i]=0; d[1][2]=1;d[2][1]=1; d[2][3]=2;d[3][2]=2; d[3][4]=3;d[4][3]=3; d[4][1]=4;d[1][4]=4; for(int i=1;i<=N;i++){ for(int j=1;j<=N;j++){ for(int k=1;k<=N;k++){ printf("d[%d][%d]=min(d[%d][%d],d[%d][%d]+d[%d][%d]);\n" ,j,k,j,k,j,i,i,k); printf("d[%d][%d]=min(%d,%d+%d) = %d \n" ,j,k,d[j][k],d[j][i],d[i][k],min(d[j][k],d[j][i]+d[i][k])); d[j][k]=min(d[j][k],d[j][i]+d[i][k]); } } } cout << d[1][4] << endl; }
RECOMMEND