Hopscotch (POJ 3050 DFS)

Source: Internet
Author: User

Hopscotch
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2845 Accepted: 1995

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.
1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <Set>5#include <cstring>6 using namespacestd;7 inta[5][5];8 intN;9 intvis[5][5];Ten intdx[]={0,0,-1,1},dy[]={-1,1,0,0}; One Set<int>se; A intDfsintXintYintSintnum) - { -     if(s==6) the     { -         //cout<<num<<endl; - Se.insert (num); -         return 0; +     } -      for(intI=0;i<4; i++) +     { A         intnx=x+Dx[i]; at         intny=y+Dy[i]; -         if(nx>=0&&ny>=0&&nx<=4&&ny<=4&&vis[nx][ny]==0) -         { -         //vis[nx][ny]=1; -DFS (nx,ny,s+1, num*Ten+A[nx][ny]); -         //vis[nx][ny]=0; in         } -     } to     return 0; + } - intMain () the { *     inti,j; $Freopen ("In.txt","R", stdin);Panax Notoginsengmemset (Vis,0,sizeof(Vis)); -      for(i=0;i<5; i++) the          for(j=0;j<5; j + +) +scanf"%d",&a[i][j]); A      for(i=0;i<5; i++) the          for(j=0;j<5; j + +) +         { -             //vis[i][j]=1; $DFS (I,J,1, A[i][j]); $             //vis[i][j]=0; -         } -printf"%d\n", Se.size ()); the //set<int>::iterator A=se.begin (); -     /*For (; A!=se.end (); a++)Wuyi     { the cout<<*a<<endl; -     }*/ Wu}

Hopscotch (POJ 3050 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.