CodeForces - 1245 C - Constanze's Machine
| 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
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'.
这个题是斐波那契数列+累乘法求方案数,就行了,同样是o(N+1E5)的复杂度,就别说什么DP快,DP好的了。
n=1 ,cnt=1
n=2, cnt=2
n=3, cnt=3
n=4, cnt=5
n=5, cnt=8
n是连续的字符数量 cnt是能够组成几种解读方式。累乘求和即可。
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
#define ll long long
char s[100004];
ll fb[100005];
int main()
{
ll c=1,t1=0,t2=0;
cin>>s;
fb[2]=2,fb[3]=3;
for(ll i=4; i<=100000; i++)
fb[i]=(fb[i-1]+fb[i-2])%1000000007;
ll l=strlen(s);
for(ll i=0; i<l; i++)
{
if(s[i]=='m'||s[i]=='w')
{
cout<<0;
return 0;
}
if(s[i]=='u')
{
if(t2>1)
{
c=(c*fb[t2])%1000000007;
}
t1++;
t2=0;
continue;
}
if(s[i]=='n')
{
if(t1>1)
{
c=(c*fb[t1])%1000000007;
}
t2++;
t1=0;
continue;
}
if(s[i]!='u'&&s[i]!='n')
{
if(t1>1)
{
c=(c*fb[t1])%1000000007;
}
if(t2>1)
{
c=(c*fb[t2])%1000000007;
}
t1=0,t2=0;
}
}
if(t1>1)
{
c=(c*fb[t1])%1000000007;
}
if(t2>1)
{
c=(c*fb[t2])%1000000007;
}
cout<<c<<endl;
return 0;
}
CodeForces - 1245 C - Constanze's Machine的更多相关文章
- Codeforces Round #597 (Div. 2) C. Constanze's Machine
链接: https://codeforces.com/contest/1245/problem/C 题意: Constanze is the smartest girl in her village ...
- 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 ...
- codeforces Codeforces Round #597 (Div. 2) Constanze's Machine 斐波拉契数列的应用
#include<bits/stdc++.h> using namespace std; ]; ]; ; int main() { dp[] = ; scanf(); ); ; i< ...
- CodeForces - 1245 B - Restricted RPS(贪心)
Codeforces Round #597 (Div. 2) Let nn be a positive integer. Let a,b,ca,b,c be nonnegative integers ...
- Codeforces 1245 E. Hyakugoku and Ladders
传送门 显然这个图是个 $DAG$ ,那么就可以考虑跑 $dp$ 了 先考虑没有梯子的情况,首先把每个位置标号,越后面的位置编号越小,终点位置编号为 $1$ 那么从终点往起点 $dp$ ,枚举当前位置 ...
- Codeforces 1245 D. Shichikuji and Power Grid
传送门 经典的最小生成树模型 建一个点 $0$ ,向所有其他点 $x$ 连一条边权为 $c[x]$ 的边,其他任意两点之间连边,边权为 $(k_i+k_j)(\left | x_i-x_j\right ...
- Codeforces Round #597 (Div. 2)
A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...
- CodeForces 164C Machine Programming 费用流
Machine Programming 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co One remark ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组
E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...
随机推荐
- 抓包工具fiddler安装和配置
常见的抓包工具:fiddler.wireshark,本文以安装fiddler为例: 在官网上https://www.telerik.com/fiddler下载,安装后打开fiddler. 选择好自己的 ...
- 如何增加Tomcat内存
有时候在开发中,常常遇到内存溢出问题,很有可能项目过大,导致Tomcat内存不足问题,那么此时就要给Tomcat添加内存了,如,操作如下 1. 先找到Tomcat目录下的catalina.bat文件
- 34.1 字符流-- FileRead FileWrite
一次读取一个字符 FileReader fr = new FileReader("aa.txt"); // System.out.println(fr.read()); // Sy ...
- 两个div在同一行显示
栅格系统需要引用bootstrap插件 <script src="~/Scripts/BootStrap/bootstrap.js"> </script> ...
- web.xml被文件加载过程,各节点加载顺序总结
web.xml被文件加载过程,各节点加载顺序总结 博客分类: J2EE WebXMLSpringServletBean 今天2010-3-11日,上班无事,想来将web.xml项目描述文件的加载过程 ...
- Mac Jenkins+fastlane 简单几步实现iOS自动化打包发布 + jenkins节点设置
最近在使用jenkins 实现ios自动化打包发布蒲公英过程实践遇到了一些坑,特意记录下来方便有需要的人. 进入正题: 一.安装Jenkins 1.Mac上安装Jenkins 遇到到坑 因为 Jenk ...
- 使用Docker快速搭建PHP开发环境
最近有个同事找过来,希望我对在很早之前写的一个PHP网站上增加一些功能,当时开发使用xampp构建的本地开发环境,但是现在我的笔记本电脑已经更新,没有当时的开发环境.本着尽量不往电脑上装无用软件的原则 ...
- 使用SVGDeveloper画svg地图详细过程
使用步骤 1. 安装svg 2. 具体操作 1. 打开svg,点击file ,new,默认svg,点击ok 显示界面如下: 然后点击image 把鼠标放到代码下面的的桌面上,鼠标箭头会变成 ...
- 使用SVG内置API计算图形或点经过transform之后的新坐标
一个应用场景是,点击一条路径,显示该路径的控制点.因为有transform变形( 平移.缩放.倾斜.旋转等变换),所以获取变形后的新坐标需要计算. 纯数学的方法,就是用2D变换矩阵的一些公式去运算,过 ...
- 极简教程!教你快速将K3s与Cloud Controller集成
作者: Dawid Ziolkowski,云原生工程师 原文链接: https://itnext.io/how-to-integrate-k3s-with-the-cloud-controller-3 ...