>> how to find all permutations of string with repeated characters.like
aabc.
idea is backtracking, complexity isn't very good
#include <cstdio>
#include <cstring>
using namespace std;
const int MX = 1000;
char str[MX], sol[MX];
bool seen[MX] = {0};
void print(int n, int k=0) {
if(k==n) {
sol[n] = 0; printf("%s\n", sol);
return;
}
int mk[256] = {0};
for(int i = 0; i < n; i++) {
if(!seen[i]&& !mk[str[i]]) {
sol[k] = str[i];
mk[str[i]] = 1;
seen[i] = 1; print(n, k+1); seen[i] = 0;
}
}
}
int main() {
scanf("%s", &str);
print(strlen(str));
}
On Thu, Jul 28, 2011 at 1:31 AM, Kamakshii Aggarwal
<[email protected]>wrote:
> how to find all permutations of string with repeated characters.like aabc.
>
> --
> Regards,
> Kamakshi
> [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.