标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2845 | Accepted: 1995 |
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
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <set> 5 #include <cstring> 6 using namespace std; 7 int a[5][5]; 8 int n; 9 int vis[5][5]; 10 int dx[]={0,0,-1,1},dy[]={-1,1,0,0}; 11 set<int> se; 12 int dfs(int x,int y,int s,int num) 13 { 14 if(s==6) 15 { 16 //cout<<num<<endl; 17 se.insert(num); 18 return 0; 19 } 20 for(int i=0;i<4;i++) 21 { 22 int nx=x+dx[i]; 23 int ny=y+dy[i]; 24 if(nx>=0&&ny>=0&&nx<=4&&ny<=4&&vis[nx][ny]==0) 25 { 26 // vis[nx][ny]=1; 27 dfs(nx,ny,s+1,num*10+a[nx][ny]); 28 // vis[nx][ny]=0; 29 } 30 } 31 return 0; 32 } 33 int main() 34 { 35 int i,j; 36 freopen("in.txt","r",stdin); 37 memset(vis,0,sizeof(vis)); 38 for(i=0;i<5;i++) 39 for(j=0;j<5;j++) 40 scanf("%d",&a[i][j]); 41 for(i=0;i<5;i++) 42 for(j=0;j<5;j++) 43 { 44 //vis[i][j]=1; 45 dfs(i,j,1,a[i][j]); 46 //vis[i][j]=0; 47 } 48 printf("%d\n",se.size()); 49 // set<int>::iterator a=se.begin(); 50 /*for(;a!=se.end();a++) 51 { 52 cout<<*a<<endl; 53 }*/ 54 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/5151266.html