CodeForces 1084C The Fair Nut and String

版权声明:博主的博客不值钱随便转载但要注明出处 https://blog.csdn.net/easylovecsdn/article/details/85004226

题意:
统计序列个数,序列满足,要么是a,要么首尾是a中间至少一个b。

思路:
b将a分为了不同区段(x1, x2, x3...xn),运用组合数学ans = (x1 + 1) * (x2 + 1) * (x3 + 1)... * (xn + 1) - 1,其他字母可以无视,你仔想想就知道为啥了。

Code:

#include <bits/stdc++.h>

#define pause system("pause")

using namespace std;

typedef long long LL;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;


int main()
{
	char c;
	LL ans = 1;
	int sum = 0;
	while ((c = getchar()) != '\n')
	{
		if (c == 'a') sum++;
		else if (c == 'b')
		{
			ans *= (sum + 1);
			ans %= mod;
			sum = 0;
		}
	}
	ans *= (sum + 1);
	ans -= 1;
	ans %= mod;
	cout << ans << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/easylovecsdn/article/details/85004226