首页 技术 正文
技术 2022年11月15日
0 收藏 908 点赞 2,788 浏览 1586 个字

Kinds of Fuwas


Time Limit:
2 Seconds      Memory Limit:65536 KB


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 integerT (1 <=T
<= 50) which is the number of test cases. And it will be followed byT consecutive test cases.

The first line of each test case has two integersM andN (1 <=M,N
<= 250), which means the number of rows and columns of the Fuwa matrix. And then there areM lines, each hasN
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
http://blog.csdn.net/mengxiang000000/article/details/51169341题目大意:给你一个n*m的矩阵,里边有五种福娃,让你在图中找四个角都是一样福娃的矩形个数。思路:我们枚举两行,这样如果上边一行和下边一行的相同位子字母相同的话,这样就保证了有一条边符合矩形了。假如这样的两行:BBBBBBBB一共有四条竖着的边符合条件,辣么能够组成多少个矩形呢?用排列组合的话来说,很简单,就是Cn2.辣么我们这个时候只要枚举三层for即可。
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,909
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,434
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,249
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,060
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,692
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,730