1. Title Description: Click to open the link
2. Problem-Solving ideas: Use DFS to solve the problem. DFS is performed for each lattice, and when cur==6, the synthesized integers are placed in the set and the set size is finally output.
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std; #define N 6int g[n][n];int a[n];int dx[] = {-1, 1, 0, 0};int dy[] = {0, 0,-1, 1};set<int>base;bool inside (int x, int y) {return (x >= 0 && y &G t;= 0 && x < 5 && y < 5); }void dfs (int x, int y, int cur) {if (cur = = 6) {int sum = 0;for (int i = 0; i < cur; i++) sum = sum * + a[i];base.inse RT (sum);} Else{a[cur] = g[x][y];for (int i = 0; i < 4; i++) {int NX = x + dx[i], NY = y + dy[i];if (Inside (NX, NY)) DFS (NX, NY, cur + 1);}}} int main () {//freopen ("T.txt", "R", stdin), String Str;while (Getline (cin,str)) {base.clear (); memset (A, 0, sizeof (a)); StrinGstream SS (str); int x, i = 0;while (ss >> x) g[0][i++] = x;for (int i = 1; i < 5; i++) {getline (cin, str); int j = 0 ; StringStream SS (str); while (ss >> x) g[i][j++] = x;} for (int i = 0; i < 5;i++) for (int j = 0; J < 5; j + +) Dfs (i, j, 0); cout << base.size () << Endl;} return 0;}
Hopscotch POJ 3050