其实针对最后输出排序:
将路径(int)Stack[n]保存到(char)S[i]中,按字符串对S[i]进行排序,就能得到符合要求的输出结果了。
[cpp]
#include
#include
#include
typedef struct child
{
int num;
int w;
}child;
typedef struct node
{
int w;
int top;
child c[200];
}node;
node A[200];
int cmp(const void *a,const void *b)
{
child *aa=(child *)a;
child *bb=(child *)b;
return bb->w-aa->w;
}
int cmp1(const void *a,const void *b)
{
return strcmp((char *)b,(char *)a);
}
int Stack[200],top,sum,s;
char S[200][200];
int tops[200],nu;
void dfs(int k)
{
int i;
sum+=A[k].w;
Stack[top++]=A[k].w;
if(A[k].top==0)
{
if(sum==s)
{
tops[nu]=top;
S[nu][i]=Stack[i];
S[nu][i]='\0';
nu++;
}
}
else