CF Constanze's Machine【简单dp】

题目链接: https://codeforces.com/problemset/problem/1245/C

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

ouuokarinn

output

4

input

banana

output

1

input

nnn

output

3

input

amanda

output

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

题意:uu可以替换为w,nn可以替换为m,给你一个序列,问你一共有多少种序列。特殊:序列种出现w,m则直接输出0

题解:dp[i]描述从左到右第i个字符时一共有多少种序列。若dp[i] = dp[i - 1] && dp[i] == 'u' || 'n',则状态转移方程dp[i] = dp[i - 1] + dp[i - 2],否则dp[i] = dp[i - 1]。 

初始化:dp[0] = 1

拿序列ouuokarinn举例: dp[0] = 1,dp[1] = dp[i - 1] = dp[0] = 1,dp[2] = dp[i - 1] + dp[i - 2] = dp[1] + dp[0] = 2......

特殊点:若uu、nn在序列开始,则特判一下

#include
using namespace std;
const int mod = 1e9+7;

int main(){
    string s;
    cin >> s;
    int flag = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'm' || s[i] == 'w')
            flag = 1;
    }
    int dp[100009];
    dp[0] = 1;
    for(int i = 1; i < s.size(); i++){
        if(i == 1)
            if(((s[i] == 'u' && s[i - 1] == 'u') || (s[i] == 'n' && s[i - 1] == 'n')))
                dp[1] = (dp[0] + 1) % mod;
            else
                dp[i] = dp[i - 1] % mod;
        else if(s[i] == s[i - 1] && (s[i] == 'u' || s[i] == 'n'))
            dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
        else
            dp[i] = dp[i - 1] % mod;
    }
    int x = s.size();
    if(flag == 1)
        cout << '0' << endl;
    else
        cout << dp[x - 1] << endl;
    return 0;
}

 

你可能感兴趣的:(动态规划)