Mahmoud_Hawara

Untitled

Jun 15th, 2026
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #pragma GCC optimize("-Ofast")
  4. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
  5. #pragma GCC optimize("-ffast-math")
  6. #pragma GCC optimize("-funroll-loops")
  7. #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
  8. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  9.  
  10. const long long MOD = 1e9 + 7;
  11.  
  12. int n, k;
  13. string a;
  14.  
  15. bool is_palindrome(const string &s)
  16. {
  17. int l = 0, r = (int)s.size() - 1;
  18. while (l < r)
  19. {
  20. if (s[l] != s[r]) return false;
  21. l++;
  22. r--;
  23. }
  24. return true;
  25. }
  26.  
  27. int main()
  28. {
  29. IO
  30.  
  31. cin >> n >> k >> a;
  32.  
  33. long long ans = 0;
  34.  
  35. for (int mask = 0; mask < (1 << n); mask++)
  36. {
  37. if (__builtin_popcount(mask) != k) continue;
  38.  
  39. string cur = "";
  40. for (int i = 0; i < n; i++)
  41. {
  42. if ((mask >> i) & 1) continue;
  43. cur += a[i];
  44. }
  45.  
  46. if (is_palindrome(cur))
  47. {
  48. ans++;
  49. if (ans >= MOD) ans -= MOD;
  50. }
  51. }
  52.  
  53. cout << ans % MOD;
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment