Codeforces Round #597 (Div. 2) C. Constanze's Machine
链接:
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的更多相关文章
- 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 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在区 ...
- 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 ...
随机推荐
- RocketMq 集群方式搭建 步骤教学包教包会
mq集群方式搭建 有段时间没写这些技术文章了, 今天抽空写一点,不然自己都快忘记了 这篇文章记录了rocketmq 集群方式搭建的过程, 也是自己半天的成果记录吧! 感兴趣的朋友点个赞在走呗! 好了, ...
- Hystrix【入门】
公共依赖配置: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...
- 转:数据库实例自动crash并报ORA-27157、ORA-27300等错误
rhel7.2上安装12C RAC数据库后,其中一个数据库实例经常会自动crash.查看alert日志发现以下错误信息: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Errors ...
- 字典的学习2——参考Python编程从入门到实践
遍历字典 1. 遍历所有键值对 eg1: user_0 = { 'username': 'efermi', 'first': 'enrico', 'last': 'fermi',}for key, v ...
- vue的安装配置与项目创建
1,安装vue必须先安装node.js. --------去官网安装node.js 因为npm依赖node.js环境,使用npm的时候需要安装node.js.安装node.js的时候npm会默认安装 ...
- Linux下 sftp服务配置
查看openssh的版本,使用ssh -V 命令来查看openssh的版本,版本必须大于4.8p1,低于的这个版本需要升级. 参考博客:https://yq.aliyun.com/articles/6 ...
- shell 学习笔记7-shell-函数
一.函数 1.什么是shell函数 把相同程序段定义成函数,可以减少整个程序的代码量,提升开发效率 增加程序的可读性,易读性,提升管理效率 可以失效程序功能模块化,使程序具备可移植性 其实linux系 ...
- shell 学习笔记3-shell变量扩展
一.特殊位置参数变量 1.特殊位置参数变量 在shell中比如:$0.$1.$#,等被称为特殊位置参数变量,当命令行.函数.脚本执行等处传递参数时,就需要使用位置参数变量 参数说明如下: 2.示例$1 ...
- 【转载】在windows上部署使用Redis
下载Redis 在Redis的官网下载页上有各种各样的版本,我这次是在windows上部署的,要去GitHub上下载.目前的是2.8.12版的,直接解压,在\bin\release 目录下有个压缩包, ...
- asp.net后台或前端获取TemplateField绑定的文本
GridView中使用最多的一个是BoundField,还有一个是TemplateField 这两个各有其特点,BoundField的话比较简单,设置好DataField.HeaderText等就可以 ...