题解 | 串
串
https://www.nowcoder.com/practice/01c35f01fb7343fe9fc16139562f78ed
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9 + 7; const int MAXN = 1e6 + 10; int f[MAXN] = {0,26}; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 2; i <= n; i++) f[i] = (f[i-1] * 26) % MOD; //小学生应用题,当长度为1时: int x = 25,y = 1;//先设x为不含u的串,然后y为含u的串 //设u为未知是因为要符合子序列us int ans = 0; for(int i = 2; i <= n; i++) { int new_x= (x * 25) % MOD; //不含u的串为不合法的 int new_y = (y * 25 + x) % MOD; //含u但不含s int legal = (f[i] - (new_x + new_y + MOD)%MOD + MOD) % MOD;//出去不合法的就是合法的了 ans = (ans + legal) % MOD; //继承状态为下一层做准备 x = new_x; y = new_y; } cout << ans << endl; return 0; }