Skip to content

Commit

Permalink
Merge pull request #52 from AlgoLeadMe/13-Redish03
Browse files Browse the repository at this point in the history
13-Redish03
  • Loading branch information
Redish03 authored Feb 16, 2024
2 parents c3cd6f8 + 4c8bdc1 commit 7585ca3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
65 changes: 65 additions & 0 deletions Redish03/Backtracking/15663.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <iostream>
#include <algorithm>

using namespace std;

int arr[10];
int N, M;
int current[8];
int previ[8];
bool used[8];

bool check_duplicate()
{
for (int i = 0; i < M; i++)
{
if (current[i] != previ[i])
{
return false;
}
}
return true;
}

void find_arr(int count)
{
if (count == M)
{
if (check_duplicate())
{
return;
}
for (int i = 0; i < M; i++)
{
previ[i] = current[i];
cout << current[i] << " ";
}
cout << '\n';

return;
}

int tmp = 0;
for (int i = 0; i < N; i++)
{
if (used[i] || tmp == arr[i])
continue;
current[count] = arr[i];
tmp = arr[i];
used[i] = true;
find_arr(count + 1);
used[i] = false;
}
}

int main()
{
cin >> N >> M;
for (int i = 0; i < N; i++)
{
cin >> arr[i];
}
sort(arr, arr + N);

find_arr(0);
}
3 changes: 2 additions & 1 deletion Redish03/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| 9차시 | 2024.01.25 | Back tracking | [N과 M(7)](https://www.acmicpc.net/problem/15656) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/35) |
| 10차시 | 2024.01.28 | DP | [내려가기](https://www.acmicpc.net/problem/2096) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/41) |
| 11차시 | 2024.01.31 | Greedy | [삼각형 만들기](https://www.acmicpc.net/problem/1448) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/44) |
| 12차시 | 2024.02.03 | DP | [구간 합 구하기 5](https://www.acmicpc.net/problem/11660) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/44) |
| 12차시 | 2024.02.03 | DP | [구간 합 구하기 5](https://www.acmicpc.net/problem/11660) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/47) |
| 13차시 | 2024.02.06 | Back tracking | [N과 M(9)](https://www.acmicpc.net/problem/15663) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-5/pull/47) |

---

0 comments on commit 7585ca3

Please sign in to comment.