C. Constanze's Machine(斐波那契数列+整数相乘)

C. Constanze's Machine

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Constanze is the smartest girl in her village but she has bad eyesight.

One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses.

However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did.

The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper.

The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense.

But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got.

But since this number can be quite large, tell me instead its remainder when divided by 109+7109+7.

If there are no strings that Constanze's machine would've turned into the message I got, then print 00.

Input

Input consists of a single line containing a string ss (1≤|s|≤1051≤|s|≤105) — the received message. ss contains only lowercase Latin letters.

Output

Print a single integer — the number of strings that Constanze's machine would've turned into the message ss, modulo 109+7109+7.

Examples

input

Copy

ouuokarinn

output

Copy

4

input

Copy

banana

output

Copy

1

input

Copy

nnn

output

Copy

3

input

Copy

amanda

output

Copy

0

Note

For the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn".

For the second example, there is only one: "banana".

For the third example, the candidate strings are the following: "nm", "mn" and "nnn".

For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.

【题意】

我们可以发现(以‘m’, ‘nn’ 为例,另一个同理)
当有2个连续的 ‘n’
共有两种情况:‘nn’, ‘m’
当有3个连续的 ‘n’
共有三种情况: ‘nnn’, ‘nm’, ‘mn’
当有4个连续的 ‘n’
共有五种情况: ‘nnnn’, ‘nnm’, ;nmn’, ‘mnn’, ‘mm
可以看出:f[i]=f[i-1]+f[i-2];

正好是斐波那锲数列。

最后,我们就可以将所有含两个或两个以上的‘n’, 或‘u’的种数相乘 (利用乘法原理)

AC代码:

#include <iostream>
#include <cstring>
using namespace std;
const int mod=1e9+7;
const int maxn=1e5+6;
typedef long long ll;
ll f[maxn];
void init()
{
    f[1]=1;
    f[2]=2;
    for(int i=3;i<maxn;i++)
    {
        f[i]=(f[i-1]+f[i-2])%mod;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    init();
    string s;
    while(cin>>s)
    {
    int len=s.size();
    int ans=1,cnt=0;
    for(int i=0;i<len;i++)
    {
        if(s[i]=='w'||s[i]=='m')
        {
            ans=0;
            break;
        }
        else if(i==0||s[i]==s[i-1]&&(s[i]=='n'||s[i]=='u'))
        {
            cnt++;
        }
        else
        {
            ans=(ans*f[cnt])%mod;
            cnt=1;
        }
    }
    ans=(ans*f[cnt])%mod;
    cout<<ans<<endl;
    }
    return 0;
}

这种思维题还是得多练啊!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值