前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CodeForces - 1245 C - Constanze's Machine

CodeForces - 1245 C - Constanze's Machine

作者头像
风骨散人Chiam
发布2020-10-28 11:29:47
5800
发布2020-10-28 11:29:47
举报
文章被收录于专栏:CSDN旧文

Codeforces Round #597 (Div. 2)

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

代码语言:javascript
复制
ouuokarinn

Output

代码语言:javascript
复制
4

Input

代码语言:javascript
复制
banana

Output

代码语言:javascript
复制
1

Input

代码语言:javascript
复制
nnn

Output

代码语言:javascript
复制
3

Input

代码语言:javascript
复制
amanda

Output

代码语言:javascript
复制
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'.

这个题是斐波那契数列+累乘法求方案数,就行了,同样是o(N+1E5)的复杂度,就别说什么DP快,DP好的了。

n=1 ,cnt=1

n=2, cnt=2

n=3, cnt=3

n=4, cnt=5

n=5, cnt=8

n是连续的字符数量 cnt是能够组成几种解读方式。累乘求和即可。

代码语言:javascript
复制
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
#define ll long long
char s[100004];
ll fb[100005];
int main()
{
    ll c=1,t1=0,t2=0;
    cin>>s;
    fb[2]=2,fb[3]=3;
    for(ll i=4; i<=100000; i++)
        fb[i]=(fb[i-1]+fb[i-2])%1000000007;
    ll l=strlen(s);
    for(ll i=0; i<l; i++)
    {
        if(s[i]=='m'||s[i]=='w')
        {
            cout<<0;
            return 0;
        }
        if(s[i]=='u')
        {
            if(t2>1)
            {
                c=(c*fb[t2])%1000000007;
            }
            t1++;
            t2=0;
            continue;
        }
        if(s[i]=='n')
        {
            if(t1>1)
            {
                c=(c*fb[t1])%1000000007;
            }
            t2++;
            t1=0;
            continue;
        }
         if(s[i]!='u'&&s[i]!='n')
        {
            if(t1>1)
            {
                c=(c*fb[t1])%1000000007;
            }
            if(t2>1)
            {
                c=(c*fb[t2])%1000000007;
            }
            t1=0,t2=0;
        }
    }
    if(t1>1)
    {
        c=(c*fb[t1])%1000000007;
    }
    if(t2>1)
    {
        c=(c*fb[t2])%1000000007;
    }
    cout<<c<<endl;
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/11/06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档