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 ...
随机推荐
- 37.3 net--TcpDemo1 大小写转换
需求:使用TCP协议发送数据,并将接收到的数据转换成大写返回 启动方式:先打开服务端,再打开客户端 客户端 package day35_net_网络编程.tcp传输; import java.io.I ...
- hadoop(八)集群namenode启动ssh免密登录(完全分布式五)|10
前置章节:hadoop集群配置同步(hadoop完全分布式四)|10 启动namenode之前: 1. 先查看有无节点启动,执行jps查看,有的话停掉 [shaozhiqi@hadoop102 ~]$ ...
- 理解JSON:3分钟课程
理解JSON:3分钟课程 博客分类: Java综合 jsonAjaxJavaScriptXMLLISP 本文是从 Understanding JSON: the 3 minute lesson 这篇文 ...
- js使用经验--遍历
目的 在平常的前端开发中,一般需要处理数据(数组和对象居多),特别是复杂功能的页面,通常是一到两个对象数组(有时数组里面还有数组).大多数前端开发的难点就是这里,耗时大.以前我在工作中,遇到的支付方式 ...
- python初学(三)
1.以软科中国最好大学排名为分析对象,基于requests库和bs4库编写爬虫程序,对2015年至2019年间的中国大学排名数据进行爬取,并按照排名先后顺序输出不同年份的前10位大学信息,要求对输出结 ...
- 今天我们来谈谈绝对定位和相对定位的区别,和需要注意的问题;position:absolute|relative;
首先position:absolute|relative; 前者是绝对定位,后者是相对定位: position属性的四个值: static,relative,fixed,absolute; 重点重点重 ...
- 8. react 常用组件
griddle-react react-bootstrap react-cropper core-js Material UI superagent restful-error-es6 browser ...
- CTFHub web技能树 RCE
一个简单的ping,还没有过滤,源码也给出来了 ls一下 127.0.0.1 & ls 有一个可疑的php文件,,,但是直接访问和 cat 都出不来... 试了几下反弹shell,没成功... ...
- [一道蓝鲸安全打卡Web分析] 文件上传引发的二次注入
蓝鲸打卡的一个 web 文件上传引发二次注入的题解和思考 蓝鲸文件管理系统 源代码地址:http://www.whaledu.com/course/290/task/2848/show 首先在设置文件 ...
- beanshell 常用的内置变量与函数
官方详细文档:https://github.com/beanshell/beanshell/wiki log:用来记录日志文件 log.info("jmeter"); vars - ...