This is a training reference for the solution of small petition violence
Topic Link http://acm.hust.edu.cn/vjudge/problem/19832
Thinking of solving problems
In the small white Book of the generation arrangement of the program, there may be elements to repeat.
Code
#include <stdio.h>#include<string.h>#include<algorithm>using namespacestd;Const intMaxLen = the;CharP[maxlen];voidPrint_permutation (intNChar*a,intcur) { if(cur = = N) {A[cur] =' /'; printf"%s\n", a); } for(intI=0; i<=n; i++)if(!i | | p[i]!=p[i-1]) { intc1=0, c2=0; for(intj=0; j<cur; J + +)if(A[j]==p[i]) c1++; for(intj=0; j<n; J + +)if(P[j]==p[i]) c2++; if(c1<C2) {A[cur]=P[i]; Print_permutation (n, a, cur+1); } }}intMain () {intN; scanf ("%d", &N); for(intI=0; i<n; i++) { CharA[maxlen]; scanf ("%s", p); Sort (p, p+strlen (p)); Print_permutation (Strlen (p), A,0); printf ("\ n"); } return 0;}
uva10098-fast generation of ordered permutations