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 ...
随机推荐
- Hystrix【参数配置及缓存】
1.常用参数说明 hystrix参数的详细配置可参照 https://github.com/Netflix/Hystrix/wiki/Configuration 下面是一些常用的配置: 配置项 默认值 ...
- jdbc连接oracle的三种方法
jdbc连接oracle的三种方法 使用service_name,配置方式:jdbc:oracle:thin:@//<host>:<port>/<service_name ...
- Python 容器用法整理
本文整理几种基本容器:列表.元组.字典和集合的用法和collections中几种已经预先实现的容器数据结构:namedtuple(),双向链表deque,ChainMap,Counter,Ordere ...
- Python重要配置大全
PYTHON 环境安装 安装虚拟环境 pip install virtualenv 卸载包是用:pip uninstall virtualenv 快捷下载安装可用豆瓣源,方法为: pip instal ...
- Redis客户端、服务端的安装以及命令操作
目的: redis简介 redis服务端安装 redis客户端安装 redis相关命令操作 redis简介 官网下载(https://redis.io/) Redis 是完全开源免费的,遵守BSD协议 ...
- maven一些简单常用却容易记混的命令参数-U -e -B
install 命令完成了项目编译.单元测试.打包功能,同时把打好的可执行jar包(war包或其它形式的包)布署到本地maven仓库,但没有布署到远程Maven私服仓库: deploy 命令完成了项目 ...
- NEST指定id
1.默认以Id属性为Id,无Id属性则自动生成 2.可通过属性标签指定Id [ElasticsearchType(IdProperty = nameof(last_name))] public cla ...
- 关于使用sublime的一些报错异常退出的解决方法
1.我用Sublime Text 3,装了一些插件,现在一打开软件就提示plugin_host has exited unexpectedly,如下图 解决方案 :
- 链接标签<a>去掉下划线
1.去掉下划线 text-decoration:none:
- 【Java】接口和抽象类总结
一.接口 1.1 成员变量(其实是常量) 1.2 方法 二.抽象类 2.1 成员变量 2.2 方法 一.接口 1.1 成员变量(其实是常量) 成员变量默认用 public static final修饰 ...