若干个u,两个u可以换成一个w,共有多少种方式
uu有两种情况:uu、w
uuu有三种情况:uuu、wu、uw
uuuu有五种情况
以此类推,就是一个斐波那契
代码:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
stack<ll> st;
ll mod=1000000007;
ll f[500000];
int main()
{
f[2]=2;f[3]=3;
for(int i=4;i<500000;i++)
{f[i]=(f[i-1]+f[i-2])%mod;}
string s;
cin>>s;
int n=s.size();
ll flag=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='m'||s[i]=='w')
{flag=1;}
}
if(flag)
{cout<<"0"<<endl;
return 0;}
ll ans=1;
int i=0;
while(i<n)
{
if(s[i]=='u')
{
int j;
for(j=i+1;j<n;j++)
{
if(s[j]!='u')
{break;}
}
ll op=j-i;
st.push(op);
i=j;
continue;
}
if(s[i]=='n')
{
int j;
for(j=i+1;j<n;j++)
{
if(s[j]!='n')
{break;}
}
ll op=j-i;
st.push(op);
i=j;
continue;
}
i++;
}
ll cnt=1;
while(!st.empty())
{
ll op=st.top();st.pop();
if(op<2)
{continue;}
cnt=cnt*f[op]%mod;
}
cout<<cnt%mod<<endl;
return 0;
}