/*给一个5*5的矩阵
*从某一个位置开始能够向上下左右走
*求所有走了6步后,走过的矩阵元素(数字)的序列
*/
#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<sstream>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF=0x3f3f3f3f;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
set<int> s;
int G[5][5];
int num[6];
int ans;
void dfs(int x, int y, int n){
if(n >= 6){
ans = 0;
for(int i = 0; i < 6; i++){
ans = ans * 10 + num[i];
}
s.insert(ans); //答案塞进一个set可以去重
return;
}
for(int i = 0; i < 4; i++){
int nx = x + dx[i], ny = y + dy[i];
if(nx >= 0 && nx < 5 && ny >= 0 && ny < 5){
num[n] = G[nx][ny];
dfs(nx, ny, n + 1);
}
}
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
//ios::sync_with_stdio(false);
for(int i = 0; i < 5; i++)
for(int j = 0; j < 5; j++)
cin >> G[i][j];
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5; j++){
dfs(i, j, 0);
}
}
cout << s.size() << endl;
return 0;
}
POJ 3050(Hopscotch 穷竭搜索)
最新推荐文章于 2020-05-07 11:19:02 发布