Created
January 5, 2019 12:36
-
-
Save fpdjsns/92ce5fc97f0fb363b588979ba8628c97 to your computer and use it in GitHub Desktop.
[SW Expert Academy] 2819. 격자판의 숫자 이어 붙이기 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV7I5fgqEogDFAXB&categoryId=AV7I5fgqEogDFAXB&categoryType=CODE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
#include<algorithm> | |
#include<vector> | |
#include<set> | |
using namespace std; | |
int n = 4; | |
set<string> setNum; | |
int dx[4] = { -1,1,0,0 }; | |
int dy[4] = { 0,0,-1,1 }; | |
vector<vector<int>> arr; | |
void getSum(int x, int y, int cnt, string s) { | |
s += arr[x][y]+'0'; | |
cnt++; | |
if (cnt == 7) { | |
setNum.insert(s); | |
return; | |
} | |
for (int i = 0; i < 4; i++) { | |
int nx = x + dx[i]; | |
int ny = y + dy[i]; | |
if (nx < 0 || n <= nx || ny < 0 || n <= ny) continue; | |
getSum(nx, ny, cnt, s); | |
} | |
} | |
int main() { | |
int t; | |
cin >> t; | |
for (int c = 1; c <= t; c++) { | |
setNum = set<string>(); | |
arr = vector<vector<int>>(4, vector<int>(4)); | |
for (int i = 0; i < n; i++) | |
for (int j = 0; j < n; j++) | |
cin >> arr[i][j]; | |
for (int i = 0; i < n; i++) | |
for (int j = 0; j < n; j++) | |
getSum(i, j, 0, ""); | |
printf("#%d %d\n", c, setNum.size()); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment