題意:給定一個字符串,如果在該字符串中存在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;
}