题解:P16804 [蓝桥杯 2026 国 Python A] 键盘失灵
ToastBread · · 题解
定义
显然有
考虑
直接 DP 算答案即可。答案为
:::info[计算答案(C++)]
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 998244353
int f[30000005],su[30000005],tot=1;
signed main()
{
f[0]=su[0]=1;
for(int i = 1; i <= 2025; i++)
{
f[i]=(26*f[i-1])%mod;
su[i]=(su[i-1]+f[i])%mod;
tot*=26;
tot%=mod;
}
for(int i = 2026; i <= 20260606; i++)
{
f[i]=((25*(su[i-1]-su[i-2026]))%mod+mod)%mod;
su[i]=(su[i-1]+f[i])%mod;
tot*=26;
tot%=mod;
}
cout<<((tot-f[20260606])%mod+mod)%mod;
}
::: :::info[计算答案(Python)]
mod = 998244353
def solve():
n = 20260606
f = [0] * (n + 1)
su = [0] * (n + 1)
tot = 1
f[0] = su[0] = 1
for i in range(1, 2026):
f[i] = (26 * f[i-1]) % mod
su[i] = (su[i-1] + f[i]) % mod
tot = (tot * 26) % mod
for i in range(2026, n + 1):
f[i] = ((25 * (su[i-1] - su[i-2026])) % mod + mod) % mod
su[i] = (su[i-1] + f[i]) % mod
tot = (tot * 26) % mod
result = (tot - f[n]) % mod
result = (result + mod) % mod
print(result)
if __name__ == "__main__":
solve()
:::
:::info[输出答案(C++,Python)]
C++
```cpp
#include<bits/stdc++.h>
using namespace std;
signed main()
{
cout<<338867718<<endl;
}
Python
print("338867718")
:::
AI 使用说明:本题解使用了 DeepSeek 进行 C++ 至 Python 代码的转换。