The way of the horse

Source: Internet
Author: User

Describe

On a 4x5 board, the position of the horse's starting position coordinates (longitudinal, transverse) is entered by the keyboard, and the horse can return to the total number of different methods of the initial position (the horse passes the position can not be repeated, the horse Walk "Day" word).

Input

Input file first behavior test Case number N, next n rows, two positive integers per line x, y (1<=x<=5,1<=y<=6), represents the position coordinates of the horse .

Output

The output of each test case is one row, and the output horse can return the total number of all different walks in its initial position, and if not, output "ERROR" (without double quotes).

Sample input

3
2 2
1 1
4 6

Sample output

4596
1508
ERROR
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 intm, N;6 intdx[]={1,1,-1,-1,2,2,-2,-2};7 intdy[]={2,-2,2,-2,1,-1,1,-1};8 intmap[5][6];9 intSX, Sy, step;Ten  One voidDfsintXinty) A { -     intxx, yy, I; -      for(i =0; I <8; i++) the     { -xx = x +Dx[i]; -yy = y +Dy[i]; -         if(xx>=0&& yy>=0&& xx<4&& yy<5&& Map[xx][yy] = =0)     +         { -MAP[XX][YY] =1; + DFS (XX,YY); AMAP[XX][YY] =0; at         } -         if(xx+1==sx&&yy+1==Sy) -step++; -     } - } -  in intMain () - { to           intN; +            while(cin>>N) -           { the                while(n--) *               { $Cin>>sx>>Sy;Panax Notoginseng                   if(sx<1|| Sx>4|| sy<1|| Sy>5) -                   { theprintf"error\n"); +                       Continue; A                   } thememset (Map,0,sizeofmap); +Step =0; -map[sx-1][sy-1] =1; $DFS (sx-1, sy-1); $printf"%d\n", step); -               } -           } the           return 0; -}

The way of the horse

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.