| 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;
}

本文介绍了一种处理商店订单并确定访问仓库顺序的算法。该算法接收一系列商品订单,这些订单已按字母顺序分类并存储在相应的仓库中。通过使用标准模板库(STL)和回溯法实现所有可能的仓库访问顺序,并确保输出结果按字母顺序排列。
439

被折叠的 条评论
为什么被折叠?



