链接:

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. Prometheus入门到放弃(2)之Node_export安装部署

    1.下载安装 node_exporter服务需要在三台机器都安装,这里我们以一台机器为例: 地址:https://prometheus.io/download/ ### 另外两个节点部署时,需要先创建 ...

  2. Apache Shiro初认识

    Apache Shiro 一.Shiro介绍: Apache软件基金会专门针对系统中的登录.加密.权限认证.授权等等功能进行了封装,不仅仅适用于JavaWeb项目,CS架构的系统也可以使用Shiro. ...

  3. FZU2018级算法第五次作业 m_sort(归并排序或线段树求逆序对)

    首先对某人在未经冰少允许情况下登录冰少账号原模原样复制其代码并且直接提交的赤裸裸剽窃行为,并且最终被评为优秀作业提出抗议! 题目大意: 给一个数组含n个数(1<=n<=5e5),求使用冒泡 ...

  4. PAT(B) 1071 小赌怡情(Java)

    题目链接:1071 小赌怡情 (15 point(s)) 题目描述 常言道"小赌怡情".这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大 ...

  5. 1010 Radix:猥琐的测试数据

    谨以此题纪念边界测试数据浪费了我多少时间:https://pintia.cn/problem-sets/994805342720868352/problems/994805507225665536 # ...

  6. Oracle创建视图权限不足

    Oracle 在创建用户的时候如果直接给用户DBA权限,那么在B用户中可以直接查询A用户的表,但是在创建视图时就会报无权限,在这种情况下需要再在被访问的A用户里面去给予要访问该表的B用户授权. --创 ...

  7. 全栈项目|小书架|服务器开发-Koa全局路由实现

    什么是路由 路由就是具体的访问路径,指向特定的功能模块.一个api接口是由ip(域名)+端口号+路径组成,例如 :https://www.npmjs.com/package/koa-router就是一 ...

  8. The Art Of Loving

    The Art Of Loving 来源 https://www.zhihu.com/question/23720541 ----------------------------- 茫然的蒲公英 有书 ...

  9. Html CSS transform matrix3d 3D转场特效

    Html CSS transform matrix3d 3D转场特效 透视矩阵 2n/(r-l) 0 (r+l)/(r-l) 0 0 2n/(t-b) (t+b)/(t-b) 0 0 0 (n+f)/ ...

  10. TR-银行主数据相关BAPI

    BAPI_BANKDETAIL_CREATE FI01:BAPI_BANK_CREATE FI12:BAPI_HOUSE_BANK_REPLICATE 1011 Business Object Ban ...