POJ 3050 Hopscotch "DFS"

Source: Internet
Author: User

Hopscotch
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2156 Accepted: 1548

Description

The cows play the child's game of hopscotch in a non-traditional. Instead of a linear set of numbered boxes into which to hop, the cows create a 5x5 rectilinear grid of digits parallel to The X and Y axes.

They then adroitly hop onto any digit in the grid and hop forward, backward, right, or left (never diagonally) to another Digit in the grid. They hop again (same rules) to a digit (potentially a digit already visited).

With a total of five intra-grid hops, their hops create a six-digit integer (which might has leading zeroes like 000201).

Determine the count of the number of distinct integers that can is created in this manner.

Input

* Lines 1..5:the grid, five integers per line

Output

* Line 1:the number of distinct integers so can be constructed

Sample Input

1 1 1 1 11 1 1 1 11 1 1 1 11 1 1 2 11 1 1 1 1

Sample Output

15

Hint

OUTPUT DETAILS:
111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111, 121112, 121211, 121212, 211111, 211121, 212111, and 212121 can be constructed. No other values is possible. Data too water, simple deep search

Code:

 #include < cstdio> #include <cstring>const int dx[] = {0, 0, 1, -1};const int dy[] = {1,-1, 0, 0};int ans, num, map[10][10];        BOOL Vis[1000000];void DFS (int x, int y, int cur, int step) {if (step = = 6) {if (!vis[cur]) {vis[cur] = 1;        ++ans;    } return;    } int i;        for (i = 0; i < 4; i + +) {int NX = x+dx[i]; int ny = y+dy[i]; if (nx<0| | nx>=5| | ny<0| |        NY>=5) continue;    DFS (NX, NY, Cur*10+map[nx][ny], step+1);    }}void Sol () {ans = 0;    int I, J;            for (i = 0; i < 5; i + +) {for (j = 0; J < 5; J + +) {//printf ("fdjkl");        DFS (I, J, Map[i][j], 1);    }}}int Main () {int i, J;   for (i = 0; i < 5; i + +) for (j = 0; J < 5; j + +) scanf ("%d", &map[i][j]);    printf ("dfgjk\n");    Sol ();    printf ("%d\n", ans); return 0;} 


POJ 3050 Hopscotch "DFS"

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.