码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #597 (Div. 2) C dp

时间:2020-05-27 20:13:41      阅读:48      评论:0      收藏:0      [点我收藏+]

标签:efi   cout   sign   字符   deb   ons   技术   str   size   

技术图片


设dpi为前面长度为i的字符串的所有可能组合,如果 s[i]==s[i-1]并且s[i]∈{u,n}
那么dp[i]=dp[i-1]+dp[i-2]否则dp[i]=dp[i-1],最后结果就是dp[s[i].length]


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define rep(i,j,k) for(LL i=(j); i<(k); ++i)
#define pb push_back
#define PII pair<LL,LL>
#define PLL pair<long long, long long>
#define ini(a,j) memset(a,j,sizeof a)
#define rrep(i,j,k) for(LL i=j; i>=k; --i)
#define fi first
#define se second
#define LL long long
#define beg begin()
#define ed end()
#define all(x) x.begin(),x.end()
const LL mod= 1e9+7;
const unsigned int N = 1e5+10;
string s;
LL dp[N];
int main(int argc, char const *argv[])
{
	// #define DEBUG
    	#ifdef DEBUG
		freopen("1.dat","r",stdin);
		freopen("ans.dat","w",stdout);
	#endif
	LL _=1;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// cin>>_;
	while(_--){
		cin>>s;
		if(count(all(s),‘m‘)!=0||count(all(s),‘w‘)!=0)
			cout<<0<<endl;
		else{
			int n = s.length();
			dp[0]=1;
			dp[1]=1;
			// for(int i=)
			rep(i,1,n)
			{
				if(s[i]==‘n‘&&s[i-1]==‘n‘)
					dp[i+1]=dp[i]+dp[i-1];
				else if(s[i]==‘u‘&&s[i-1]==‘u‘)
					dp[i+1]=dp[i]+dp[i-1];
				else
					dp[i+1]=dp[i];
				dp[i+1] %= mod;
			}
			cout<<dp[n]%mod<<endl;
		}
	}
	return 0;
}

Codeforces Round #597 (Div. 2) C dp

标签:efi   cout   sign   字符   deb   ons   技术   str   size   

原文地址:https://www.cnblogs.com/Crossea/p/12975962.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!