Advertisement
Guest User

Untitled

a guest
Mar 14th, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int calc(int n, int m, int k)
  5. {
  6. if (n*m%k) return 0;
  7. unordered_set<string> ans;
  8. vector<int> v;
  9. int bins = n*m/k;
  10. for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) v.push_back(i);
  11. do
  12. {
  13. vector<string> cur;
  14. for (int i = 0; i < bins; i++)
  15. {
  16. string bin;
  17. for (int j = i*k; j < i*k+k; j++) bin += 1+v[j];
  18. sort(bin.begin(), bin.end());
  19. cur.push_back(bin);
  20. }
  21. sort(cur.begin(), cur.end());
  22. string f;
  23. for (auto &u : cur) f += u;
  24. ans.insert(f);
  25. } while (next_permutation(v.begin(), v.end()));
  26. return ans.size();
  27. }
  28.  
  29. int main()
  30. {
  31. const int colWidth = 8, N = 4, M = 4, K = 6;
  32. auto start = chrono::high_resolution_clock::now();
  33. for (int k = 2; k <= K; k++)
  34. {
  35. cout << "\nk=" << k << "\n\n";
  36.  
  37. cout << setw(colWidth) << " ";
  38. for (int n = 1; n <= N; n++) cout << setw(colWidth) << "n=" + to_string(n);
  39. cout << '\n';
  40.  
  41. for (int m = 2; m <= M; m++)
  42. {
  43. cout << setw(colWidth) << "m=" + to_string(m);
  44. for (int n = 1; n <= N; n++) cout << setw(colWidth) << calc(n, m, k);
  45. cout << '\n';
  46. }
  47. }
  48.  
  49. auto stop = chrono::high_resolution_clock::now();
  50. cout << "\nTime taken: " << chrono::duration_cast<chrono::seconds>(stop-start);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement