codeforces#597 C. Constanze's Machine(简单dp)
生活随笔
收集整理的這篇文章主要介紹了
codeforces#597 C. Constanze's Machine(简单dp)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:給定一個字符串,如果在該字符串中存在m或w時,輸出0,否則,求存在u和n的字符串有多少種方案數。
思路:
#include<bits/stdc++.h>using namespace std; typedef long long LL;const int maxn = 1e5+5; const int mod = 1e9+7; char s[maxn]; LL dp[maxn];int main() {scanf("%s", s);int len = strlen(s);for(int i = 0; i < len; i++){if(s[i] == 'm' || s[i] == 'w'){printf("0\n");return 0;}}dp[0] = dp[1] = 1;for(int i = 1; i < len; i++){if(s[i] == s[i-1]){if(s[i] == 'u' || s[i] == 'n')dp[i+1] = (dp[i] + dp[i-1]) % mod;else dp[i+1] = dp[i];}else dp[i+1] = dp[i];}printf("%lld\n", dp[len]);return 0; }?
總結
以上是生活随笔為你收集整理的codeforces#597 C. Constanze's Machine(简单dp)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: codeforces#597 D. Sh
- 下一篇: 最大子段和(动态规划及分治法)