fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long c[105][105],vt[100000],n,tt=INT_MAX,s=0,d[100000];
  4. void hv(long long i)
  5. {
  6. for (long long j=1;j<=n;j++)
  7. {
  8. if (d[j]==0)
  9. {
  10. vt[i]=j;
  11. d[j]=1;
  12. s+=c[vt[i]][vt[i-1]];
  13. if (i==n)
  14. tt=min(tt,s+c[vt[i]][1]);
  15. else
  16. hv(i+1);
  17. d[j]=0;
  18. s-=c[vt[i]][vt[i-1]];
  19. }
  20. }
  21. }
  22.  
  23. int main() {
  24. freopen("banhang.inp","r",stdin);
  25. freopen("banhang.out","w",stdout);
  26. cin>>n;
  27. for (long long i=1;i<=n;++i)
  28. for (long long j=1;j<=n;j++)
  29. cin>>c[i][j];
  30. vt[1]=1;
  31. d[1]=1;
  32. hv(2);
  33. cout<<tt;
  34. return 0;}
  35.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty