#include #include using namespace std; double bi(double a,double b){ if(a==0) return b; if(b==0) return a; return aj 的直飞路径,已用优惠券数 double f[101][21] = { 0 };//距离1最短距离,已用优惠券数 cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> a[i][j]; } } for (int i = 1; i <= n; i++) { f[i][0] = a[1][i]; f[i][1] = a[1][i] / 2; ge[i]=1; } //重复n次保证全部轮过 for (int e = 1; e <= n; e++) { //当前起点 for (int i = 1; i <= n; i++) { //当前终点 if (f[i][0] > 0) { for (int j = 1; j <= n; j++) { if (a[i][j] > 0) { if(ge[i]+1<=m) ge[i]++; for (int k = 0; k <= ge[i]; k++) { f[j][k]=bi(f[j][k],f[i][k]+a[i][j]); if(k!=m){ f[j][k+1]=bi(f[j][k+1],f[i][k]+a[i][j]/2); f[j][k+1]=bi(f[j][k],f[j][k+1]); } } } } } } } double ans=f[n][0]; for(int i=1;i<=m;i++){ if(ans>f[n][i]&&f[n][i]!=0){ ans=f[n][i]; } } printf("%0.1f",ans); }