递归 Permute
递归
计算所有(1..4)的排序方法
perl pm
use Algorithm::Permute;
my $p = new Algorithm::Permute(['1'..'4']);
while(my @n=$p->next){print @n,"\n"}
c
label.insert(term);
for(int i=1; i<Nord; i++) {
count = 0;
for(int j=0; j<nterm[i-1]; j++) {
memcpy(term, label[hie_start[i-1]+j], Ng+1);
term[Ng]++;
for(int k=0; k<Ng; k++) {
term[k] += 1;
rt=0.0;
double pref = 1;
for(int l=0; l<Ng; l++) {
rt += term[l]*creal(gamma[l]);
pref *= exp(fct[l]*term[l])/my_gamma[term[l]+1];
}
if(rt < hcut) {
int inserted = label.insert(term);
count += inserted;
#if 0
if(inserted) {
printf("%8d", i);
for(int l=0; l<=Ng; l++) {
printf("%4d", static_cast<int>(term[l]));
}
printf("\n");
}
#endif
}
if(rt<hcut && pref < 1.e-06) nk++;
term[k] -= 1;
}
}
if(count > nterm[i]) abort();
nterm[i] = count;
hie_start[i] = hie_start[i-1] + nterm[i-1];
}