Advertisement
Josif_tepe

Untitled

Apr 18th, 2023
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <map>
  5. #include <cstring>
  6. #include <queue>
  7. #include <algorithm>
  8. //#include <bits/stdc++.h>
  9. using namespace std;
  10. const int maxn = 22;
  11. int n;
  12. char mat[maxn][maxn];
  13. int main() {
  14.     ios_base::sync_with_stdio(false);
  15.     cin >> n;
  16.     vector<int> v;
  17.     for(int i = 0; i < n; i++) {
  18.         v.push_back(i);
  19.         for(int j = 0; j < n; j++) {
  20.             cin >> mat[i][j];
  21.         }
  22.     }
  23.     int res = 2e9;
  24.    
  25.     do {
  26.         int switched = 0;
  27.         for(int i = 0; i < n; i++) {
  28.             for(int j = 0; j < i; j++) {
  29.                 if(mat[v[i]][v[j]] == 'D') {
  30.                     switched++;
  31.                 }
  32.             }
  33.         }
  34.         res = min(res, switched);
  35.     } while(next_permutation(v.begin(), v.end()));
  36.  
  37.     cout << res << endl;
  38.     return 0;
  39. }
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement