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 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.
Input
Input consists of a single line containing a string s (1≤|s|≤105) — the received message. s contains only lowercase Latin letters.
Output
Print a single integer — the number of strings that Constanze's machine would've turned into the message s, modulo 109+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'.
题意
现在有个机器,会把w翻译成uu,把m翻译成nn。
现在给你一个字符串,让你还原成原来的样子,问你有多少种还原方式。
另外:如果字符串种存在w或者m,输出-1
题解
dp,两种转移,保持不变和变w/变m,转移即可。
代码
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int maxn = 1e5+7;
string s;
int dp[maxn];
int flag = 0;
int main(){
cin>>s;
int flag = 0;
dp[0]=1;
if(s[0]=='m'||s[0]=='w')flag = 1;
for(int i=1;i<s.size();i++){
dp[i]=dp[i-1];
if(s[i]=='m'||s[i]=='w')flag = 1;
if((s[i]=='u'&&s[i-1]=='u')||(s[i]=='n'&&s[i-1]=='n')){
if(i==1){
dp[i]=(dp[i]+1)%mod;
}else{
dp[i]=(dp[i]+dp[i-2])%mod;
}
}
}
if(flag==1){
cout<<"0"<<endl;
}else{
cout<<dp[s.size()-1]%mod<<endl;
}
}
Codeforces Round #597 (Div. 2) C. Constanze's Machine dp的更多相关文章
- 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 #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #597 (Div. 2)
A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...
- codeforces Codeforces Round #597 (Div. 2) Constanze's Machine 斐波拉契数列的应用
#include<bits/stdc++.h> using namespace std; ]; ]; ; int main() { dp[] = ; scanf(); ); ; i< ...
- 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 ...
- 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 ...
- Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring
链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: ...
- Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 题解 最小生成树
题目链接:https://codeforces.com/contest/1245/problem/D 题目大意: 平面上有n座城市,第i座城市的坐标是 \(x[i], y[i]\) , 你现在要给n城 ...
- 计算a^b==a+b在(l,r)的对数Codeforces Round #597 (Div. 2)
题:https://codeforces.com/contest/1245/problem/F 分析:转化为:求区间内满足a&b==0的对数(解释见代码) ///求满足a&b==0在区 ...
随机推荐
- ccf再卖菜
https://blog.csdn.net/imotolove/article/details/82777819 记忆化搜索,还不太理解..
- linux编程fcntl获取和设置文件状态
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> ...
- Ubuntu 16.04 安装 mujoco, mujoco_py 和 gym
Mujoco (1)官网(https://www.roboti.us/license.html)注册 license,教育邮箱注册可以免费使用一年.注意:一个邮箱账号只能供一台主机使用. 填写个人信息 ...
- 实用小工具:VNC的安装
安装xen时,需要使用vnc工具来进行图形化安装,安装好后启动失败,试了很多办法,最终解决. 1.使用yum安装:yum install tigervnc-server tigervnc-server ...
- spring cloud 2.x版本 Sleuth+Zipkin分布式链路追踪
前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...
- 安装 Java
1.rpm下载地址 https://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm?AuthParam=1570520 ...
- docker-mysql-使用docker运行mysql8
1, 下载镜像, 我用的是8 docker pull mysql: 2, 启动镜像 docker run \ --name mysql8 \ -p : \ -v /Users/wenbronk/Con ...
- Redis for OPS 05:哨兵HA Sentinel
写在前面的话 上一节的主从环境能够解决我们保证数据安全性的问题,但是却无法解决我们在主节点挂掉的时候服务继续使用的问题,同时也不能自动切换新的主. 我们运维的目的肯定是希望即使主库挂掉一个,服务依旧能 ...
- 由 ToString()和Convert.ToString() 引发的问题
对于久经沙场的程序猿来说,类型转换再熟悉不过了,在代码中我们也会经常用到. 前几天,有个学生问我关于类型转换ToString()和Convert.ToString()的区别,这么常用的东西我竟然支支吾 ...
- Nginx反向代理实现负载均衡以及session共享
随着社会的发展和科技水平的不断提高,互联网在人们日常生活中扮演着越来越重要的角色,同时网络安全,网络可靠性等问题日益突出.传统的单体服务架构已不能满足现代用户需求.随之而来的就是各种分布式/集群式的服 ...