//https://vjudge.net/contest/537670#problem/E
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 2e6 + 10;
/*
对于字符串s,要判断它是否为字符串T的字串的方法:从左到右贪心的去匹配,有一个能匹配就匹配
题解:将问题转化为有多少长度为n+k的字符串使得s是其子序列,
枚举s最后在T中匹配的位置(是贪心的匹配),记作x,对于x之后的位置放什么字母都可以,在x之前选择n-1个位置作为s贪心匹配的位置,那么对于非匹配位置,非匹配位置只要不和下一个匹配位置选择相同的字母即可
*/
ll mod = 1e9 + 7;
ll fac[N], invfac[N];
ll qpow(ll base, ll pow)
{
ll ans = 1;
while (pow)
{
if (pow & 1)
ans = ans * base % mod;
pow >>= 1;
base = base * base % mod;
}
return ans;
}
void init()//不能忘记init和调N的大小
{
fac[0] = invfac[0] = 1;
for(int i = 1; i < N; i ++ )
fac[i] = fac[i - 1] * i % mod;
invfac[N - 1] = qpow(fac[N - 1], mod - 2);
for(int i = N - 2; i >= 0; i -- )
invfac[i] = invfac[i + 1] * (1 + i) % mod;
}
ll C(int n, int m)
{
if (n < 0 || m < 0 || m > n)
return 0;
return fac[n] * invfac[m] % mod * invfac[n - m] % mod;
}
void solve()
{
init();
int k;
cin >> k;
string s;
cin >> s;
int n = s.size();
ll ans = 0;
for(int x = n; x <= n + k; x++)
ans = (ans + C(x - 1, n - 1) * qpow(25, x - n) % mod * qpow(26, n + k - x) % mod) % mod;
cout << ans << '\n';
}
signed main()
{
IOS;
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
Strivore(计数,字符串)
最新推荐文章于 2024-07-12 18:56:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)