zoukankan      html  css  js  c++  java
  • Codeforces 1245C Constanze's Machine

    思路:

    1.设dp[i]是连续的iun最多能还原成的字符串个数;
    2.观察相邻几个i之间的关系,不难得出递推式:dp[i+2]=dp[i+1]+dp[i] (i>=2)
    3.字符串里不能出现wm,出现了输出0;
    4.最后所有情况相乘,记得中间每一步取余防止溢出;

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MAX_N=100005;
    const LL MOD=(LL)1e9+7;
    LL dp[MAX_N]={1,1,2,3};//dp[2]=2,dp[3]=3
    int main(){
    	for(int i=4;i<MAX_N;i++) dp[i]=(dp[i-1]+dp[i-2])%MOD;
    	string s;
    	cin>>s;
    	for(char c:s){
    		if(c=='w'||c=='m'){
    			putchar('0');
    			return 0;
    		}
    	}
    	LL cnt=1,ans=1;
    	for(int i=1;i<s.length();i++){
    		if(s[i]==s[i-1]&&(s[i]=='u'||s[i]=='n')) cnt++;
    		else{
    			ans*=dp[cnt];
    			ans%=MOD;
    			cnt=1;
    		}
    	}
    	if(cnt!=1) ans*=dp[cnt];
    	cout<<(ans%MOD);
    	return 0;
    }
    
  • 相关阅读:
    转载的,讲解java.util的集合类
    LinkedList
    数据结构
    随笔
    spring boot初步尝试
    spring boot
    java8 新特性
    volatile 续
    java 线程基础学习
    java 基础
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308878.html
Copyright © 2011-2022 走看看