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 ...
随机推荐
- 015 Android md5密码加密及其工具类
1.md5加密介绍 MD5算法是广泛使用的杂凑函数,也就是哈希函数,英文全拼是:Message Digest Algorithm,对应的中文名字是消息摘要算法. MD5加密:将字符串转换成 32位的字 ...
- Cortex_m7内核cache深入了解和应用
一,cache概述 从下图可以看出,从M7内核才开始有的cache,这对于从M0,M3,M4一路走来的小伙伴来说,多了一个cache就多了一个障碍. Cortex-M7 core with 32K/3 ...
- flutter从入门到精通三
flutter可以通过一套代码运行在多个平台上,包括移动,web,桌面,嵌入式,但是在 Web 平台的支持尚未达到 Beta 阶段,请不要用在生产环节,在阅读文档时候,推荐大家阅读https://fl ...
- Authentication failed for "http://xxxxxx"
1.配置用户信息 git config --global user.name [username] git config --global user.email [email] 2.查询用户信息 ...
- 线程二(Monitor)
Monitor 类的命名空间是 System.Threading,它的用法和 lock 本质是一样的. 使用 Monitor 类锁定资源的代码如下. Monitor.Enter(object); tr ...
- Centos6 Connect WiFi
Centos6 Connect WiFi // 安装 wireless tools yum install wireless-tools dkms pciutils lsusb // 使用wlan命令 ...
- 怎样修改element-ui中的样式?
方法一 方法二 使用 /deep/ .homePage /deep/ .el-main { padding: 0; } .homePage为我们要修改组件类名的父级组件样式类名..即使定义一个空的 ...
- iOS - 回顾总结Runtime原理及使用
runtime简介 因为Objc是一门动态语言,所以它总是想办法把一些决定工作从编译连接推迟到运行时.也就是说只有编译器是不够的,还需要一个运行时系统 (runtime system) 来执行编译后的 ...
- TortoiseSVN-1.7.12.24070-x64-svn-1.7.9安装包和汉化包
链接:https://pan.baidu.com/s/1NbrQW44N_kTh7VN0Fz0zVA 提取码:nhd9 先安装TortoiseSVN-1.7.12.24070-x64-svn-1.7. ...
- map函数的应用
map函数在Python中的应用 函数介绍: map() 会根据提供的函数对指定序列做映射. map(function, iterable, ...) 第一个参数function 以参数序列中的每一个 ...