题解 | 分割序列

分割序列

https://www.nowcoder.com/practice/f49a64748c2344c1be65f9be417a495a

#include<bits/stdc++.h>
using namespace std;
#define int long long

const int P=1e9+7;

int n;
string s;

void solve(){
	
	int ans=1,cnt;
	s=s+" ";
	for(int i=0;i<n;i++){
		cnt=0;
		if(s[i]=='1'&&s[i+1]=='0'){
			cnt=1;i++;
			while(i<n&&s[i+1]=='0'){
				cnt++;
				i++;
			}
			if(i==n-1){
				break;
			}
			ans=ans*(cnt+1)%P;
		}
	}
	if(n!=1) cout<<ans<<endl;
	else cout<<0<<endl;
	return;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>n;
	cin>>s;
	
	solve();
	
    return 0;
}


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务