zoukankan      html  css  js  c++  java
  • 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
    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'.

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
    #define mem(s,t) memset(s,t,sizeof(s))
    #define pq priority_queue
    #define pb push_back
    #define fi first
    #define se second
    #define ac return 0;
    #define ll long long
    #define cin2(a,n,m)     for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j];
    #define rep_(n,m)  for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
    #define rep(n) for(int i=1;i<=n;i++)
    #define test(xxx) cout<<"  Test  " <<" "<<xxx<<endl;
    #define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
    #define lc now<<1
    #define rc now<<1|1
    #define ls now<<1,l,mid
    #define rs now<<1|1,mid+1,r
    #define half no[now].l+((no[now].r-no[now].l)>>1)
    #define ll long long
    #define inf 0x3f3f3f3f
    #define mod 1000000007
    const int mxn = 2e5+10;
    int n,m,k,ans,col,t,flag;
    ll dp[mxn],pro[mxn],cnt;
    string str,ch ;
    map<char,int>mp;
    pair <int,int> pa[mxn];
    bool cmp(pair<int,int>x,pair<int,int>y) {return x.first>y.first;}
    int main()
    {
        dp[1]=1,dp[2]=2;
        for(int i=3;i<=100005;i++)
            dp[i]=(dp[i-1]+dp[i-2])%mod;
        while(cin>>str)
        {
            ans = 1;flag=1;
            for(int i=00;i<str.size();)
            {
                if(str[i]=='m' || str[i]=='w')
                {cout<<0<<endl;flag=0;break;}
                else if(str[i]=='n' || str[i]=='u')
                {
                    char c = str[i];
                    n=1;
                    for(i=i+1;i<str.size();i++)
                    {
                        if(str[i]==c)
                            n++;
                        else
                            break;
                    }
                    ans = (ans*dp[n])%mod;
                }
                else
                    i++;
            }
            if(flag)
                cout<<ans%mod<<endl;
        }
        return 0;
    }
    所遇皆星河
  • 相关阅读:
    OS模块
    利用一个random模块生成一个随机验证码功能
    random模块
    模块2
    模块module
    Java笔记汇总
    学习路上——技术书籍摸爬滚打
    web前端知识汇总——持续更新
    Python之路——进入Python学习
    Python细节备忘——时常拾遗以及关键点
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11846681.html
Copyright © 2011-2022 走看看