思路
长度为
的包含子序列“us”的数量
可以分为两部分之和
1)前
字符串包含子序列“us”+随意一个字母
2)前
字符串只包含“u”不包含“s”+第len个字符为“s”
可以两个集合可得,包含“u”不包含“s”<==>总数-不包含“u”-包含“us”
两者相加为
代码
// Problem: 串
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/9981/A
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp(aa,bb) make_pair(aa,bb)
#define _for(i,b) for(int i=(0);i<(b);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define X first
#define Y second
#define lowbit(a) (a&(-a))
#define debug(a) cout<<#a<<":"<<a<<"\n"
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
const int N=1000010;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-6;
const double PI=acos(-1.0);
ll dp[N];
ll ans;
ll fpow(ll a,ll b){
if(mod==1) return 0;
ll ans=1%mod;
while(b){
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
void solve(){
dp[2]=1;
int n;cin>>n;
rep(i,3,n) {
dp[i]+=dp[i-1]*26%mod,dp[i]%=mod;
dp[i]+=((fpow(26,i-1)-fpow(25,i-1)-dp[i-1])%mod+mod)%mod,dp[i]%=mod;
}
rep(i,2,n) ans+=dp[i],ans%=mod;
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
// int t;cin>>t;while(t--)
solve();
return 0;
}

京公网安备 11010502036488号