fork download
  1. // I can't tell you what it really is,
  2. // I can only tell you what it feels like.
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5.  
  6. #define int long long
  7. #define F first
  8. #define S second
  9. #define sz(x) ((int)x.size())
  10. #define rep(i,a,n) for (int i = a; i <= n; ++i)
  11. #define all(v) v.begin(), v.end()
  12. #define pb push_back
  13. #define P pair < int, int >
  14. #define E cout << '\n'
  15.  
  16. const int mod = 1e9 + 7;
  17. const int N = 1e6 + 1;
  18.  
  19. int h[26];
  20. int dp[16][N];
  21.  
  22. inline void solve() {
  23. string s;
  24. cin >> s;
  25. int n, ans(0);
  26. cin >> n;
  27. for (char i : s) {
  28. ++h[i-'a'];
  29. }
  30. rep(i,0,n-1) {
  31. cin >> s;
  32. for (char j : s) {
  33. ++dp[i][j-'a'];
  34. }
  35. }
  36. // rep(i,0,25) {
  37. // cout << h[i] << ' ';
  38. // }
  39. // E;
  40. int x = 1<<n;
  41. for (int i = 0; i < x; ++i) {
  42. int temp[26] = {};
  43. int cnt (0);
  44. for (int j = 0; j < n; ++j) {
  45. if (i & (1<<j)) {
  46. for (int k = 0; k < 26; ++k) {
  47. temp[k] += dp[j][k];
  48. }
  49. ++cnt;
  50. }
  51. }
  52. bool f = 1;
  53. for (int j = 0; j < 26; ++j) {
  54. if (temp[j] > h[j]) {
  55. f = 0;
  56. break;
  57. }
  58. }
  59. if (f) {
  60. // cout << i << '\n';
  61. // rep(i,0,25) {
  62. // cout << temp[i] << ' ';
  63. // }
  64. // E;
  65. ans = max(ans, cnt);
  66. }
  67. }
  68. cout << ans;
  69. }
  70. signed main() {
  71. ios_base::sync_with_stdio(0);
  72. cin.tie(NULL);
  73. cout.tie(NULL);
  74. int t = 1;
  75. //cin >> t; while(t--)
  76. solve();
  77. return 0;
  78. }
Success #stdin #stdout 0s 4468KB
stdin
Standard input is empty
stdout
Standard output is empty