跳到正文

题解

题解:P10877 「KDOI-07」n1gr tS0i

zky114514约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
P10877

版本

  1. v1当前

抢题解拉

题意

对于每个字符串,可以对于 1≤l<r≤n1\le l<r\le n 的区间,翻转每个字符(00 变成 11),操作正好 nn 次。求最后不同字符串的种数。

思路

题意读出后,我开始打暴力,但打挂了。可是,调题的时候我发现,正确的样例全是 2p mod 9982443532^p\bmod 998244353。

分类讨论

n=2n=2

答案显然为 11。


n=3n=3

答案为 44。

010
001
111
000

n≥4n\ge 4

0100
0011

每一步有两种选择,答案为 2n2^n。

代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace IO {
	char ibuf[(1<<20)+1],*iS,*iT;
#define gh() getchar()
	inline long long read() {
		char ch=gh();
		long long x=0;
		bool t=0;
		while(ch<'0'||ch>'9')t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9')x=x*10+(ch^48),ch=gh();
		return t?-x:x;
	}
	inline void print(long long x) {
		if(x<0)putchar('-'),x=-x;
		if(x>9)print(x/10);
		putchar(x%10+'0');
	}
	inline char getc() {
		char ch=gh();
		while(ch<'a'||ch>'z')ch=gh();
		return ch;
	}
}
using namespace IO;
int n,t,mod=998244353;
string s;
int qp(int a, int b) {
	int res = 1 % mod;
	while (b) {
		if (b & 1) {
			res = (res * a) % mod;
		}
		b >>= 1;
		a = (a * a) % mod;
	}
	return res;
}
main() {
	t=read();
	while(t--) {
		n=read();
		cin>>s;
		if(n==2)printf("1\n");
		else if(n==3)printf("4\n");
		else cout<<qp(2,n)<<"\n";
	}
	return 0;
}
原文