-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from AlgoLeadMe/13-Redish03
13-Redish03
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
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
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); | ||
} |
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