Advertisement
Josif_tepe

Untitled

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