Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/heejung/boj/dfs/BOJ_15650/15650.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>

using namespace std;
#define MAX 9

int N, M;
int arr[MAX];
bool visited[MAX] = { 0, };

void dfs(int k) {
if (k == M) {
for (int i = 0;i < M;i++)
cout << arr[i] << " ";
cout << "\n";

}
else {
for (int i = 1; i <= N; i++) {
if (visited[i]) continue;
for (int j = 1; j <= i; j++) {
visited[j] = true;
}
arr[k] = i;
dfs(k + 1);
for (int k = 1; k < 9; k++) {
visited[k] = false;
}
}
}
}

int main() {
cin >> N >> M;
dfs(0);
}
44 changes: 44 additions & 0 deletions src/heejung/boj/dfs/BOJ_1780/1780.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include<iostream>
using namespace std;

int arr[2187][2187];
int result[3];

void solve(int x, int y, int n) {
int first = arr[x][y];
bool flag = true;

for (int i = x;i < x + n;i++) {
for (int j = y;j < y + n;j++) {
if (arr[i][y] != first) {
flag = false;
break;
}
}
}
if (flag) {
result[first + 1]++;
}
else {
for (int a = x;a < x + n;a += n / 3) {
for (int b = y;b < y + n;b += n / 3) {
solve(a, b, n / 3);
}
}
}
}

int main() {
int N;
cin >> N;
int x;
for (int i = 0;i < N;i++) {
for (int j = 0;j < N;j++) {
cin >> arr[i][j];
}
}
solve(0, 0, N);
for (int i = 0;i < 3;i++) {
cout << result[i] << '\n';
}
}
54 changes: 54 additions & 0 deletions src/heejung/boj/dfs/BOJ_1992/1992.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include<iostream>
#include<string>
using namespace std;
int arr[64][64];
int result[3];

void solve(int x, int y, int n) {
if (n == 1) {
cout << arr[x][y];
return;
}
bool one = true;
bool zero = true;
for (int i = x; i < x + n; i++) {
for (int j = y; j < y + n; j++) {
if (arr[i][j] == 1) {
zero = false;
}
if (arr[i][j] == 0) {
one = false;
}
}
}
if (one == true) {
cout << 1;
return;
}
if (zero == true) {
cout << 0;
return;
}
cout << "(";
solve(x, y, n / 2);
solve(x, y + n / 2, n / 2);
solve(x + n / 2, y, n / 2);
solve(x + n / 2, y + n / 2, n / 2);
cout << ")";

}
int main() {
int N;
cin >> N;
int x;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
for (int j = 0; j < N; j++) {
arr[i][j] = s[j] - '0';
}
}
solve(0, 0, N);


}
42 changes: 42 additions & 0 deletions src/heejung/boj/dfs/BOJ_2630/2630.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include<iostream>
using namespace std;

int arr[128][128];
int answer[2];

void sol(int x, int y, int k)
{
int start = arr[x][y];
bool flag = true;
for (int i = x;i < x+k;i++) {
for (int j = y;j < y+k;j++) {
if (arr[i][j] != start) {
flag = false;
break;
}
}
}
if(flag)
answer[start]++;
else {
for (int a = x;a < x + k;a += k/ 2) {
for (int b = y;b < y + k;b += k / 2) {
sol(a, b, k / 2);
}
}
}
}

int main() {
int N;
cin >> N;
for (int i = 0;i < N;i++) {
for (int j = 0;j < N;j++) {
cin >> arr[i][j];
}
}
sol(0, 0, N);
for (int i = 0;i < 2;i++) {
cout << answer[i] << '\n';
}
}
50 changes: 50 additions & 0 deletions src/heejung/boj/dfs/BOJ_6603/6603.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<iostream>
using namespace std;

int k;
int arr[14];

int answer[6];
int visited[14] = { 0, };
void dfs(int x) {
if (x == 6) {
for (int i = 0;i < 6;i++) {
cout << answer[i] << " ";
}
cout << "\n";
}
else {
for (int i = 0;i < k;i++) {
if (visited[i]) continue;;
for (int j = 0;j <= i;j++) {
visited[j] = true;
}
answer[x] = arr[i];
dfs(x + 1);
for (int j = 0;j < k;j++) {
visited[j] = false;
}

}
}
}


int main() {

while (true) {
cin >> k;
if (k == 0) {
break;
}
else {
for (int i = 0;i < k;i++) {
cin >> arr[i];
}
dfs(0);


}
cout << "\n";
}
}