fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. const int all = (1 << 26) - 1;
  7.  
  8. int n, c, t, ans = 0;
  9. string str;
  10. vector<int> arr;
  11.  
  12. void Search(int cur, int visited) {
  13. if (cur + 1 == n) {
  14. if (visited == all) ans++;
  15. return;
  16. }
  17. else {
  18. Search(cur+1, visited | arr[cur+1]);
  19. Search(cur+1, visited);
  20. }
  21. }
  22.  
  23. int main() {
  24. ios_base::sync_with_stdio(false);
  25. cin.tie(NULL);
  26.  
  27. cin >> n;
  28. for (int i = 0; i < n; i++) {
  29. cin >> str;
  30. c = 0;
  31.  
  32. for (const auto& s : str)
  33. c |= 1 << (s - 'a');
  34.  
  35. arr.push_back(c);
  36. }
  37.  
  38. Search(-1, 0);
  39.  
  40. cout << ans;
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 15240KB
stdin
9
the
quick
brown
fox
jumps
over
a
sleazy
dog
stdout
2