http://acm.hdu.edu.cn/showproblem.php?pid=6344
POINT:
先n2的效率把每对问卷不同的答案状压压缩完。
得到一个1<<m的数组保存了,x这个状态对应的所以答案不同的卷子有几对。
然后枚举答案,x和y 如果x&y>0,代表有贡献。
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <bitset>
using namespace std;
#define LL long long
char s[2222][12];
int kind[2222];
int num[2222];
int main()
{
int T,cas=0;
scanf("%d",&T);
while(T--){
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++){
scanf("%s",s[i]);
kind[i]=0;
for(int j=0;j<m;j++){
if(s[i][j]=='A')
kind[i]|=1<<j;
}
}
for(int j=0;j<1<<m;j++)
num[j]=0;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
num[kind[i]^kind[j]]++;
}
}
int ans=0;
for(int i=1;i<1<<m;i++){
int now=0;
for(int j=1;j<1<<m;j++){
if(i&j){
now+=num[j];
}
}
if(now>=k)
ans++;
}
printf("Case #%d: %d\n",++cas,ans);
}
return 0;
}