鏈接:https://ac.nowcoder.com/acm/contest/1076/A
來源:牛客網
給一個26進制數n,a,b,c,...,z 分別代表十進制的0, 1, 2,....,25,且這個26進制數同樣不含前綴0,比如aab非法,定義好的26進制數:數字中包含ccsu,比如bccsua是好的,但是ccasu是不好的,現在給你一個26進制數n,讓你求 a 到 n 一共有多少個好的26進制數(答案對1e9+7取模)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e4+10;
ll dp[N][5][2];
//64位,0代表沒有49,1代表有4,2代表有49
char s[N];
const ll mod=1e9+7;
int len;
ll dfs(int pos,int sta,int limit)
{
if(pos==len+1)
{
if(sta==4) return 1;
return 0;
}
if(dp[pos][sta][limit]) return dp[pos][sta][limit];
int up=limit ? (s[pos]-'a'):25;
ll ans=0;
for(int i=0;i<=up;++i)
{
int tmp=0;
if(i=='c'-'a')
{
if(sta==1) tmp=2;
else tmp=1;
}
else if(i=='s'-'a')
{
if(sta==2) tmp=3;
}
else if(i=='u'-'a')
{
if(sta==3) tmp=4;
}
if(sta==4) tmp=4;
ans=(ans+dfs(pos+1,tmp,limit&&i==up))%mod;
}
dp[pos][sta][limit]=ans;
return ans;
}
int main()
{
cin>>s+1;
len=strlen(s+1);
printf("%lld\n",dfs(1,0,1));
}