bzoj2012: [Ceoi2010]Pin

Description

给出N(2<=N<=50000)个长度为4的字符串,问有且仅有D(1<=D<=4)处不相同的字符串有几对。

Input

第1行: N,D 以下N行每行一个字符串

Output

一个数:有多少对有且仅有处不相同的字符串。
记录每个字符串出现次数以及带1..4个通配符的字符串出现次数,容斥得到答案
#include<cstdio>
int n,m;
char s[];
int _t2[][][];
int _t3[][];
int t4,ans=;
#define t3(a,b) _t3[a][b]
#define t2(a,b,c) _t2[a][b][c]
const int P=;
struct Map{
int xs[P],ys[P];
int&operator()(int a,int b,int c,int d){
int x=(((a<<|b)<<|c)<<)|d;
int w=x%P;
while(xs[w]){
if(xs[w]==x)return ys[w];
w+=;
if(w>=P)w-=P;
}
xs[w]=x;
return ys[w];
}
}t0,t1;
int main(){
scanf("%d%d",&n,&m);
for(t4=;t4<n;t4++){
scanf("%s",s);
int a=s[],b=s[],c=s[],d=s[];
if(!a||!b||!c||!d)printf("%d",a/=);
if(m==){
ans+=
-t0(a,b,c,d)++*
+t1(a,b,c,)++
+t1(a,b,d,)++
+t1(a,c,d,)++
+t1(b,c,d,)++;
}else if(m==){
int aa1,aa2,aa3;
ans+=
+(aa1=t0(a,b,c,d)++)*
-(aa2=t1(a,b,c,)++
+t1(a,b,d,)++
+t1(a,c,d,)++
+t1(b,c,d,)++)*
+(aa3=t2(a,b,)++
+t2(a,c,)++
+t2(a,d,)++
+t2(b,c,)++
+t2(b,d,)++
+t2(c,d,)++);
}else if(m==){
ans+=
-t0(a,b,c,d)++*
+(t1(a,b,c,)++
+t1(a,b,d,)++
+t1(a,c,d,)++
+t1(b,c,d,)++)*
-(t2(a,b,)++
+t2(a,c,)++
+t2(a,d,)++
+t2(b,c,)++
+t2(b,d,)++
+t2(c,d,)++)*
+t3(a,)++
+t3(b,)++
+t3(c,)++
+t3(d,)++;
}else{
ans+=
t0(a,b,c,d)++
-(t1(a,b,c,)++
+t1(a,b,d,)++
+t1(a,c,d,)++
+t1(b,c,d,)++)
+(t2(a,b,)++
+t2(a,c,)++
+t2(a,d,)++
+t2(b,c,)++
+t2(b,d,)++
+t2(c,d,)++)
-(t3(a,)++
+t3(b,)++
+t3(c,)++
+t3(d,)++)
+t4;
}
}
printf("%d\n",ans);
return ;
}
上一篇:Tomcat服务器提示:The server is temporarily unable to service your request due to maintenance downtime or capacity problems


下一篇:Kafka:ZK+Kafka+Spark Streaming集群环境搭建(十)安装hadoop2.9.0搭建HA