这个题的意识是给你一个长度为n的序列, 序列只包含小写字母, 问你每个字母最多重复出现三次的方案数是多少?我们可以使用f[n]表示长度为n的方案数, 那么f[n] = 25*(fn-1 + fn-2 + fn-3) , 代码如下:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; LL mod = 1000000007; LL f[2000+10]; int main() { f[1] = 26; f[2] = 676; f[3] = 17576; f[4] = 456950; for(int i=5; i<=2001; i++) f[i] = 25*(f[i-1]+f[i-2]+f[i-3])%mod; int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); printf("%I64d ", f[n]); } return 0; }