Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 5599 | Accepted: 3589 |
Description
You know in advance all the orders which will have to be processed by the stores manager today, but you do not know their booking order. Compute all possible ways of the visits of warehouses for the stores manager to settle all the demands piece after piece during the day.
Input
Output
Sample Input
bbjd
Sample Output
bbdj bbjd bdbj bdjb bjbd bjdb dbbj dbjb djbb jbbd jbdb jdbb
Source
#include<iostream>
using namespace std;
char s[205];
char res[205];
bool b[205];
int N;
int cmp(const void * a,const void * b)
{
return *(char * )a-*(char *)b;
}
void backtrace(int n)
{
if(n==N)
{
printf("%s/n",res);
return ;
}
int i;
for(i=0;i<N;++i)
{
if(b[i]==false)
{
res[n]=s[i];
b[i]=true;
backtrace(n+1);
b[i]=false;
while(i<(N-1) && s[i]==s[i+1])//跳过相同的字符
i++;
}
}
}
int main()
{
scanf("%s",&s);
N=strlen(s);
res[N]='/0';
qsort(s,N,sizeof(char),cmp);
memset(b,0,sizeof(b));
backtrace(0);
return 0;
}