标签:first continue ret turn pac str == amp air
思路:
很有意思的思维题。
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int check(vector<int>& v, set<pair<int, int>>& st) 4 { 5 int res = 0; 6 map<pair<int, int>, int> mp; 7 for (int i = 1; i <= 6; i++) 8 { 9 for (int j = i; j <= 6; j++) 10 { 11 mp[make_pair(i, j)] = 0; 12 } 13 } 14 for (auto it: st) 15 { 16 int a = v[it.first - 1], b = v[it.second - 1]; 17 pair<int, int> tmp(min(a, b), max(a, b)); 18 if (mp[tmp] == 0) 19 { 20 mp[tmp] = 1; res++; 21 } 22 } 23 return res; 24 } 25 int main() 26 { 27 int n, m, a, b; 28 while (cin >> n >> m) 29 { 30 set<pair<int, int>> st; 31 for (int i = 0; i < m; i++) 32 { 33 cin >> a >> b; 34 st.insert(make_pair(min(a, b), max(a, b))); 35 } 36 if (n <= 6) { cout << m << endl; continue; } 37 vector<int> a{1, 1, 2, 3, 4, 5, 6}; 38 int maxn = 0; 39 do 40 { 41 maxn = max(maxn, check(a, st)); 42 } while (next_permutation(a.begin(), a.end())); 43 cout << maxn << endl; 44 } 45 return 0; 46 }
标签:first continue ret turn pac str == amp air
原文地址:https://www.cnblogs.com/wangyiming/p/11588356.html