Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- $n=3;//длина
- $m=2;
- $a=new SplFixedArray($n);
- $out=array();
- $used=new SplFixedArray($n+1);
- rec(0);
- print_r($out);
- //count($out)=gmp_fact(n);
- function out(){
- global $a,$n,$out;
- $tmp='';
- for($i=0;$i<$n;++$i){
- $tmp.=$a[$i];
- }
- $out[]=$tmp;
- }
- function rec($inx){
- global $a,$m,$n,$used;
- if($inx==$n){
- out();
- return;
- }
- for($i=1;$i<=$n;++$i){
- if($used[$i])continue;
- $a[$inx]=$i;
- $used[$i]=true;
- rec($inx+1);
- $used[$i]=false;
- }
- }
Add Comment
Please, Sign In to add comment