下面的程序做5取3的排列组合过程,取值是3个,2个0. 哪位朋友能麻烦解答下这个程序是怎么完成各个组合的计算的呢。这个是help文档里的事例
- proc fcmp outlib=sasuser.funcs.math;
- subroutine allpermk(n, k);
- array scratch[1] / nosymbols;
- call dynamic_array(scratch, n);
- call permk(n, k, scratch, 1, 0);
- endsub;
- subroutine permk(n, k, scratch[*], m, i);
- outargs scratch;
- if m-1 = n then do;
- if i = k then
- put scratch[*];
- end;
- else do;
- scratch[m] = 1;
- call permk(n, k, scratch, m+1, i+1);
- scratch[m] = 0;
- call permk(n, k, scratch, m+1, i);
- end;
- endsub;
- run;
- quit;
- options cmplib=sasuser.funcs;
- data _null_;
- call allpermk(5, 3);
- run;
- Log Output from Recursion Example
- 1 1 1 0 0
- 1 1 0 1 0
- 1 1 0 0 1
- 1 0 1 1 0
- 1 0 1 0 1
- 1 0 0 1 1
- 0 1 1 1 0
- 0 1 1 0 1
- 0 1 0 1 1
- 0 0 1 1 1
还有在:
scratch[m] = 1;
call permk(n, k, scratch, m+1, i+1);
这个部分,难道是一直进行循环到m-1=n?这样scratch都取值是1了么?可是这个时候i=k也不成立啊,那怎么输出scratch?各位帮帮忙解释一下吧