Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1605 | Accepted: 1141 |
Description
Input
Output
Sample Input
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1
Sample Output
15
Hint
Source Code Problem: 3050 Memory: 756K Time: 235MS Language: C++ Result: Accepted Source Code #include <iostream> #include <string> #include <set> using namespace std; const int MAX = 5; set<string> result; char data[MAX][MAX]; int a[]={-1,0,1,0}, b[]={0,1,0,-1}; void DFS(int x, int y,int l,string s) { if(l==6) { result.insert(s); return ; } for(int i=0; i <4; i++) { int tempx = x+a[i], tempy=y+b[i]; if(tempx>=0 && tempx < 5 && tempy >=0 && tempy < 5) { string str = s; s += data[tempx][tempy]; DFS(tempx, tempy,l+1, s); s = str; } } return ; } void solveCase() { for(int i=0; i < 5; i++) { for(int j=0; j<5; j++) { DFS(i, j, 0, ""); } } cout << result.size() << endl; } int main() { for(int i=0; i < 5; i++) for(int j=0; j < 5; j++) cin >> data[i][j]; solveCase(); return 0; }