zoukankan      html  css  js  c++  java
  • Constanze's Machine

    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'.

    数学不好做起来真的吃力。

    刚开始不知道有这个规律,把这个用暴力实现,显然会TLE。

     斐波那契真是个神奇的东西。

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <unordered_set>
    #include <unordered_map>
    //#include <xfunctional>
    #define ll long long
    #define mod 1000000007
    using namespace std;
    int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    
    int main()
    {
        string s;
        cin >> s;
        for (int i=0;i<s.size();i++)
        {
            if (s[i] == 'w' || s[i] == 'm')
            {
                cout << 0;
                return 0;
            }
        }
        int n = s.size();
        vector<int> dp(n + 1);
        dp[0] = 1;
        dp[1] = 1;
        for (int i = 2; i <= n; ++i)
        {
            dp[i] = dp[i - 1];
            if (s[i - 1] == s[i - 2] && (s[i - 1] == 'u' || s[i - 1] == 'n'))
                dp[i] = (dp[i] + dp[i - 2]) % mod;
        }
        cout << dp[n] << '
    ';
        return 0;
    }
  • 相关阅读:
    解决了Excel的一个貌似很奇怪的问题~~~
    关闭子页面,刷新父页面
    动态控制DataGrid中的TextBox的状态及输入值!!
    C#对Oracle BLOB字段的写入读取方法
    谈恋爱,好累...
    可移植,可扩展高效Proactor模式
    When are asynchronous file writes not asynchronous...
    [转]How to support 10,000 or more concurrent TCP connections
    [转]Creating a forwarding dll
    [转]非金钱激励员工的108种手段
  • 原文地址:https://www.cnblogs.com/dealer/p/12384388.html
Copyright © 2011-2022 走看看