Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(0);
- int mat[4][4] = {{0, 10, 15, 20},
- {10, 0, 35, 25},
- {15, 35, 0 ,30},
- {20, 25, 30, 0}
- };
- int arr[] = {0, 1, 2, 3};
- int min_cost = 2e9;
- do {
- int cost = 0;
- for(int i = 0; i < 3; i++) {
- cost += mat[arr[i]][arr[i + 1]];
- }
- cost += mat[arr[3]][arr[0]];
- min_cost = min(min_cost, cost);
- } while(next_permutation(arr, arr + 4));
- cout << min_cost << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement