Codeforces 1178

A.

水题略

B.

给出一个只含有’a’,'b’,’c’的相邻字符不同的字符串 (s) ,求一个长度 (≥lfloor frac{|s|}{2} floor) 的回文子序列 (t)

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long D;
const int maxn=1000003;
int n;
D pre[maxn],suf[maxn];
char s[maxn];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1,last=0;i<=n;i++){
		pre[i]=pre[i-1];
		if(s[i]=='v')pre[i]+=bool(last),last++;
		else last=0;
	}
	for(int i=n,last=0;i>=1;i--){
		suf[i]=suf[i+1];
		if(s[i]=='v')suf[i]+=bool(last),last++;
		else last=0;
	}
	D ans=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='o')ans+=pre[i]*suf[i];
	}
	printf("%lld
",ans);
	return 0;
}

C.

用如图所示的地板铺满整个地板,要求颜色相同的部分不能相邻 ,求有多少种方法。  。

你会发现,当第一行和第一列的元素确定之后,整个矩阵的元素也就确定了。
而第一行和第一列的元素有 (2^{n+m}) 种可能。
所以答案就是 (2^{n+m})

D.

原文地址:https://www.cnblogs.com/BlogOfchc1234567890/p/11243560.html