链接:

https://codeforces.com/contest/1245/problem/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+7.

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

思路:

DP, 考虑连续两个转换的值,为Dp[i] = Dp[i-1]+Dp[i-2],否则Dp[i] = Dp[i-1]。

出现w和m时为0.

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 1e9+7;
const int MAXN = 1e5+10; string s;
LL Dp[MAXN]; int main()
{
ios::sync_with_stdio(false);
cin >> s;
int len = s.length();
Dp[0] = Dp[1] = 1;
for (int i = 1;i < len;i++)
{
if (s[i] == s[i-1] && (s[i] == 'u' || s[i] == 'n'))
Dp[i+1] = (Dp[i]+Dp[i-1])%MOD;
else
Dp[i+1] = Dp[i];
}
for (int i = 0;i < len;i++)
{
if (s[i] == 'w' || s[i] == 'm')
{
cout << 0 << endl;
return 0;
}
}
cout << Dp[len]%MOD << endl; return 0;
}

Codeforces Round #597 (Div. 2) C. Constanze's Machine的更多相关文章

  1. Codeforces Round #597 (Div. 2) C. Constanze's Machine dp

    C. Constanze's Machine Constanze is the smartest girl in her village but she has bad eyesight. One d ...

  2. Codeforces Round #597 (Div. 2)

    A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...

  3. codeforces Codeforces Round #597 (Div. 2) Constanze's Machine 斐波拉契数列的应用

    #include<bits/stdc++.h> using namespace std; ]; ]; ; int main() { dp[] = ; scanf(); ); ; i< ...

  4. Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid

    链接: https://codeforces.com/contest/1245/problem/D 题意: Shichikuji is the new resident deity of the So ...

  5. Codeforces Round #597 (Div. 2) B. Restricted RPS

    链接: https://codeforces.com/contest/1245/problem/B 题意: Let n be a positive integer. Let a,b,c be nonn ...

  6. Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring

    链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: ...

  7. Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 题解 最小生成树

    题目链接:https://codeforces.com/contest/1245/problem/D 题目大意: 平面上有n座城市,第i座城市的坐标是 \(x[i], y[i]\) , 你现在要给n城 ...

  8. 计算a^b==a+b在(l,r)的对数Codeforces Round #597 (Div. 2)

    题:https://codeforces.com/contest/1245/problem/F 分析:转化为:求区间内满足a&b==0的对数(解释见代码) ///求满足a&b==0在区 ...

  9. Codeforces Round #597 (Div. 2) F. Daniel and Spring Cleaning 数位dp

    F. Daniel and Spring Cleaning While doing some spring cleaning, Daniel found an old calculator that ...

随机推荐

  1. [转帖]鲁大师Q3季度PC内存排行:DDR3彻底淘汰 DDR5要来了

    鲁大师Q3季度PC内存排行:DDR3彻底淘汰 DDR5要来了 https://www.cnbeta.com/articles/tech/902347.htm 10月23日消息,今天鲁大师公布Q3季度P ...

  2. grpc proto文件生成java、.net实体类以及客户端代码

    背景 工作中对接对方服务是GRPC,对方只提供了proto契约文件,需要自己生成对应的实体类以及客户端代码,故记录下操作流程. Java 代码生成 实体类: 通过protoc插件生成实体类 在 htt ...

  3. php生成动态验证码 加减算法验证码 简单验证码

    预览效果: <?php /** *ImageCode 生成包含验证码的GIF图片的函数 *@param $string 字符串 *@param $width 宽度 *@param $height ...

  4. 使用keepalived实现kubenetes apiserver高可用

    # 安装 nginx yum install nginx -y # 配置nginx4层代理 /etc/nginx/nginx.conf stream { upstream kube-apiserver ...

  5. "一起来捉妖"怎么从瘸腿中组合到最合心意的妖灵

    背景: 最近两天活动,黑鬼白鬼合体觉醒秋容,陆无名,聂小倩,作为一个非土豪玩家,没有超高资质妖灵的我,想要在瘸腿妖灵中选取两个最佳选择,合体觉醒. 初选: 备选妖灵从5个维度录入数据,进行选择,分别为 ...

  6. 怎样重启ssh服务

    尝试下面两个命令: service sshd restart systemctl restart sshd.service

  7. 如何录屏做GIF图

    网上找了一下,ScreenToGif 这个神器 https://github.com/NickeManarin/ScreenToGif https://github.com/NickeManarin/ ...

  8. SQL Server存储过程中变量使用函数调用变量

    USE  DB名称GO SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO . CREATE   PROCEDURE     存储过程名 @formID   n ...

  9. Sharding-JDBC介绍

    Sharding-JDBC是当当应用框架ddframe中,从关系型数据库模块dd-rdb中分离出来的数据库水平分片框架,实现透明化数据库分库分表访问.Sharding-JDBC是继dubbox和ela ...

  10. 【转载】C#使用is关键字检查对象是否与给定类型兼容

    在C#的编程开发过程中,很多时候涉及到数据类型的转换,如果强行转换数据类型,有时候可能会出现程序运行时错误,C#语言中提供了is关键字可以检查对象是否与给定类型兼容,可先判断类型兼容后再进行对象的转换 ...