2919 Selection Questions
time limit: 1 sspace limit: 16000 KBtitle level: Golden Gold SolvingTitle Description
Description
A classmate exam, in N*m's answer card wrote a,b,c,d Four kinds of answers.
He finished, and can not pay, a look at the table, from the ring bell and N long.
He began to play a game: Select a lattice x, Y, from this grid to the 4 directions to find the same options, found again.
The area of the graph to be formed. (one option occupies one unit area)
Enter a description
Input Description
N M X Y
Answer Card (matrix)
Output description
Output Description
Area
Sample input
Sample Input
3 3 1 2
A C B
C c C
D C A
Sample output
Sample Output
5
Data range and Tips
Data Size & Hint
N,m<=15.
For 33% data, only a.
Category labels
Tags Click here to expandSearch by irrigation method
#include <cstdio>#include<iostream>using namespacestd;#defineN 101CharMap[n][n],goal;intN,m,sum,vis[n][n];voidDfsintIintj) { if(i<1|| j<1|| i>n| | J>M)return ; if(!vis[i][j]&&map[i][j]==goal) {Vis[i][j]=1; sum++; }Else return ; DFS (i+1, J); DFS (I,j+1); DFS (i-1, J); DFS (I,j-1);}intMain () {intx, y; CIN>>n>>m>>x>>y; for(intI=1; i<=n;i++){ for(intj=1; j<=m;j++) {cin>>Map[i][j]; }} goal=Map[x][y]; DFS (x, y); printf ("%d\n", sum); return 0;}
2919 Selection Questions