Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #pragma GCC optimize("-Ofast")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
- #pragma GCC optimize("-ffast-math")
- #pragma GCC optimize("-funroll-loops")
- #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- const long long MOD = 1e9 + 7;
- int n, k;
- string a;
- bool is_palindrome(const string &s)
- {
- int l = 0, r = (int)s.size() - 1;
- while (l < r)
- {
- if (s[l] != s[r]) return false;
- l++;
- r--;
- }
- return true;
- }
- int main()
- {
- IO
- cin >> n >> k >> a;
- long long ans = 0;
- for (int mask = 0; mask < (1 << n); mask++)
- {
- if (__builtin_popcount(mask) != k) continue;
- string cur = "";
- for (int i = 0; i < n; i++)
- {
- if ((mask >> i) & 1) continue;
- cur += a[i];
- }
- if (is_palindrome(cur))
- {
- ans++;
- if (ans >= MOD) ans -= MOD;
- }
- }
- cout << ans % MOD;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment