(Sort of DP bar) The magic of the small tea (Fzu 2225)

Source: Internet
Author: User

http://acm.fzu.edu.cn/problem.php?pid=2225 problem Description

After defeating Iki Probrand, Nome Probrand, Xiao Ming students began to challenge Hade Probrand.

After a battle, he launched a big wave of attacks. In order to resist the attack, the students put magic array on the side of the magic array, and then he did not know that he put a number of magic array. It takes time to reclaim the magic array, in order to withstand the next wave of attack, the small tea students need to know that they have a number of magical array, because of the urgency of the situation, the task needs to be done by you.

The Magic matrix is triangular, such as

.............

. x.. X....x ...

..... xxx. x.x.

..... xxxxx.

.............

These are all thought to be magic matrices.

(that is, the triangles are three vertices (i,j), (I+k,j-k), (I+k,j+k), and the edges are ' x '. The elements in the middle of the triangle are not required. An ' x ' can belong to more than one magical array at a time. A single ' x ' also counts as a magical array. )

The site can be thought of as a nxm rectangle, each positioned as '. ' means nothing, or ' x ' indicates a magical array.

Input

The first line is an integer t (t<=10), which represents the total T-group test data.

The first row of each set of data contains two integers, N M (n,m≤1000), representing the size of the matrix.

Next n lines, m letters per line are '. ' or ' x '.

Output

Each set of data outputs has a single row, the output format is "case #x: Y", X starts at 1, represents the data group number, and Y represents the number of corresponding magic arrays.

Sample Input1 3 3. x. xxx ...Sample OutputCase #1:5SourceFOJ Award-April 2016 (school match)

#include <cstdio>#include<queue>#include<stack>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;#defineLson 2*root#defineRson 2*root+1#defineMet (A, B) (Memset (A,b,sizeof (a)))typedefLong LongLL;ConstLL mod =1000000007;ConstLL inf= 1e9+7;Const intN =1100;CharS[n][n];intDp[n][n], dl[n][n], dr[n][n];///right, bottom left, right bottom record continuous, and finally judge can increase the large triangle, the code is very easy to readintMain () {intT, icase=1; scanf ("%d", &T);  while(t--)    {        intI, J, K, N, M, cnt=0; scanf ("%d%d", &n, &m); Met (S,0); Met (DP,0); Met (DL,0); Met (DR,0);  for(i=1; i<=n; i++) {scanf ("%s", s[i]+1);  for(j=1; j<=m; J + +)            {                if(s[i][j]=='x') {CNT++; DP[I][J]= Dl[i][j] = Dr[i][j] =1; }            }        }         for(I=n; i>=1; i--)         for(J=m; j>=1; j--)        {            if(Dp[i][j]) dp[i][j]+ = dp[i][j+1]; if(Dl[i][j]) dl[i][j]+ = dl[i+1][j-1]; if(Dr[i][j]) dr[i][j]+ = dr[i+1][j+1]; }         for(i=1; i<=n; i++)         for(j=1; j<=m; J + +)        {             for(k=1; K<=min (Dl[i][j], dr[i][j]); k++)            {                if(dp[i+k][j-k]>=2*k+1) CNT++; }} printf ("Case #%d:%d\n", icase++, CNT); }    return 0;}

(Sort of DP bar) The magic of the small tea (Fzu 2225)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.