$$ \newcommand{\seq}[2]{{#1}_{1},{#1}_{2},\cdots,{#1}_{#2}} \newcommand{\num}[1]{1,2,\cdots,#1} \newcommand{\stra}[2]{\begin{bmatrix}#1 \\ #2\end{bmatrix}} \newcommand{\strb}[2]{\begin{Bmatrix}#1 \\ #2\end{Bmatrix}} \newcommand{\dw}[1]{\underline{#1}} \newcommand{\up}[1]{\overline{#1}} $$

Codeforces 1178

A.

水题略

B.

给出一个只含有’a’,'b’,’c’的相邻字符不同的字符串 \(s\) ,求一个长度 \(≥\lfloor \frac{|s|}{2} \rfloor\) 的回文子序列 \(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\n",ans);
	return 0;
}

C.

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

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

D.

posted @ 2019-07-25 12:49  chc_1234567890  阅读(184)  评论(0编辑  收藏  举报