>> 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 <kamakshi...@gmail.com>wrote: > how to find all permutations of string with repeated characters.like aabc. > > -- > Regards, > Kamakshi > kamakshi...@gmail.com > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.