Advertisement
Josif_tepe

Untitled

Apr 27th, 2022
780
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None
  1. #include <fstream>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     ios_base::sync_with_stdio(0);
  8.     int mat[4][4] = {{0, 10, 15, 20},
  9.                     {10, 0, 35, 25},
  10.                     {15, 35, 0 ,30},
  11.                     {20, 25, 30, 0}
  12.     };
  13.     int arr[] = {0, 1, 2, 3};
  14.     int min_cost = 2e9;
  15.     do {
  16.         int cost = 0;
  17.         for(int i = 0; i < 3; i++) {
  18.             cost += mat[arr[i]][arr[i + 1]];
  19.         }
  20.         cost += mat[arr[3]][arr[0]];
  21.         min_cost = min(min_cost, cost);
  22.        
  23.     } while(next_permutation(arr, arr + 4));
  24.     cout << min_cost << endl;
  25.     return 0;
  26. }
  27.  
Advertisement
RAW Paste Data Copied
Advertisement