列表

详情


NC223864. UnitedinStormwind

描述

The adventurers gather together in the majestic capital city, Stormwind, for a referendum about the future of their alliance. The referendum contains questions, and each question has two options, and .

After collecting the results of the referendum, the alliance received survey results. When sorting out the results, Alice comes up with a special idea. She thinks that a nonempty subset of questions is if there are at least pairs of results different in at least one of the questions in the set.

She wants to know the number of different discriminative subsets of questions. Can you help Alice solve this problem?

输入描述

The first line contains three integers  , as specified in the problem statement.

Each of the following lines contains a string of length , which contains only and , indicating the answer to each question in the referendum results.

输出描述

Output a single integer that represents the number of different discriminative subsets of questions.

示例1

输入:

2 2 1
AA
BB

输出:

3

示例2

输入:

2 2 1
AA
AB

输出:

2

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 113ms, 内存消耗: 16836K, 提交时间: 2022-02-06 11:34:52

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=(1<<20)+5; 
int n,m,x,ans;
ll k,c[N],f[N];
char s[N];
void FWTxor(ll f[N],int n,int op){
	ll x,y;
	for(int k=2;k<=n;k<<=1)
		for(int i=0,m=k>>1;i<n;i+=k)
			for(int j=i;j<i+m;j++){ 
				x=f[j],y=f[j+m],f[j]=x+y,f[j+m]=x-y;
				if(op==-1) f[j]/=2,f[j+m]/=2;
			} 
}
signed main(){
	scanf("%d%d%lld",&n,&m,&k);
	for(int i=1;i<=n;i++){
		scanf("%s",s+1),x=0;
		for(int j=1;j<=m;j++) x|=(s[j]=='A')<<(j-1);
		c[x]++; 
	}
	FWTxor(c,(1<<m),1);
	for(int i=0;i<(1<<m);i++) f[i]=c[i]*c[i];
	FWTxor(f,(1<<m),-1);
	for(int i=0;i<m;i++)
		for(int j=0;j<(1<<m);j++)
			if((j>>i)&1) f[j]+=f[j^(1<<i)];
	for(int i=0;i<(1<<m);i++) ans+=(1ll*n*n-f[i]>=k*2);
	printf("%d\n",ans);
	return 0;
} 

上一题