ZOJ 2975 Kinds of Fuwas
枚举。
枚举两行,然后算这两行之间有多少个矩形满足条件。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<ctime> #include<iostream> using namespace std; typedef long long LL; const double pi=acos(-1.0); void File() { freopen("D:\\in.txt","r",stdin); freopen("D:\\out.txt","w",stdout); } template <class T> inline void read(T &x) { char c = getchar(); x = 0; while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } } int T,n,m; char s[300][300]; int main() { scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf("%s",s[i]); int ans=0; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { int B=0,J=0,H=0,Y=0,N=0; for(int k=0;k<m;k++) { if(s[i][k]=='B'&&s[j][k]=='B') B++; if(s[i][k]=='J'&&s[j][k]=='J') J++; if(s[i][k]=='H'&&s[j][k]=='H') H++; if(s[i][k]=='Y'&&s[j][k]=='Y') Y++; if(s[i][k]=='N'&&s[j][k]=='N') N++; } ans=ans+B*(B-1)/2+J*(J-1)/2+H*(H-1)/2+Y*(Y-1)/2+N*(N-1)/2; } } printf("%d\n",ans); } return 0; }