Description
In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China as well as becoming a festival for people all over the world.
The official mascots of Beijing 2008 Olympic Games are Fuwa, which are named as Beibei, Jingjing, Haunhuan, Yingying and Nini. Fuwa embodies the natural characteristics of the four most popular animals in China -- Fish, Panda, Tibetan Antelope, Swallow -- and the Olympic Flame. To popularize the official mascots of Beijing 2008 Olympic Games, some volunteers make a PC game with Fuwa.
As shown in the picture, the game has a matrix of Fuwa. The player is to find out all the rectangles whose four corners have the same kind of Fuwa. You should make a program to help the player calculate how many such rectangles exist in the Fuwa matrix.
Input
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.
The first line of each test case has two integers M and N (1 <= M, N <= 250), which means the number of rows and columns of the Fuwa matrix. And then there are M lines, each has N characters, denote the matrix. The characters -- 'B' 'J' 'H' 'Y' 'N' -- each denotes one kind of Fuwa.
Output
Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the number of the rectangles whose four corners have the same kind of Fuwa.
Sample Input
2 2 2 BB BB 5 6 BJHYNB BHBYYH BNBYNN JNBYNN BHBYYH
Sample Output
1 8
1 #include<iostream> 2 #include<string.h> 3 #include<stdio.h> 4 #include<ctype.h> 5 #include<algorithm> 6 #include<stack> 7 #include<queue> 8 #include<set> 9 #include<math.h> 10 #include<vector> 11 #include<map> 12 #include<deque> 13 #include<list> 14 using namespace std; 15 int main() 16 { 17 int a; 18 cin>>a; 19 while(a--) 20 { 21 22 int n,m,t; 23 cin>>n>>m; 24 char JU[260][260];//输入信息 25 for(int i=0;i<n;i++) 26 for(int j=0;j<m;j++) 27 cin>>JU[i][j]; 28 char wa[]={"BJHYN"}; 29 int he=0 ; 30 for(int i=0;i<n;i++) 31 for(int j=i+1;j<n;j++) 32 { 33 for(int p=0;p<5;p++) 34 { 35 t=0; 36 for(int l=0;l<m;l++) 37 if(JU[i][l]==wa[p]&&JU[j][l]==wa[p])//划线…… 38 t=t+1; 39 he=he+t*(t-1)/2;//等差数列求和 40 } 41 } 42 printf("%d\n",he); 43 } 44 return 0; 45 }